How can I get my jasmine tests fixtures to load before the javascript considers the document to be “ready”?

后端 未结 6 2494
星月不相逢
星月不相逢 2021-01-01 21:51

I am fairly certain that the issue is that the jquery bindings set to run on $(document).ready do not have the fixture html available to them. So when my events occur that

6条回答
  •  半阙折子戏
    2021-01-01 22:22

    Adding the jQuery directly to the html fixture worked for me to get the desired behavior. It is not exactly an answer to this question, but I am starting to believe it's the best solution currently available. My changes where made in the jasmine-rails gem set-up and I haven't yet tried it in the jasminerice branch.

    Here is my test file:

    describe ("my basic jasmine jquery test", function(){
    
        beforeEach(function(){
            loadFixtures('myfixture.html');
        });
    
        it ("does some basic jQuery thing", function () {
            $('a#test_link').click();
            expect($("a#test_link")).toHaveText('My test link is now longer');
        });
    
        it ("does the same basic jQuery thing with a different event initiation method", function () {
            $('a#test_link').trigger('click');
            expect($("a#test_link")).toHaveText('My test link is now longer');
        });
    
    });
    describe ('substraction', function(){
    
        var a = 1;
        var b = 2;
    
        it("returns the correct answer", function(){
            expect(substraction(a,b)).toBe(-1);
        });
    
    });
    

    And here is my fixture file:

    My test link
    
    
    

提交回复
热议问题