mercredi 9 septembre 2015

$timeout.flush() does not work in context of jasmine testing suite

I'm using $timeout.flush() to trigger a $timeout in my code. The test works fine when run independently, but throws No deferred tasks to be flushed when run with other tests (be they describes or its).

I put the code from my other tests into this block, so I know it's not a cross-test interaction issue. Has anyone else had this issue?

var $timeout;
beforeEach(inject(function (_$timeout_) {
    $timeout = _$timeout_;
}));

// Run like this it throws "No deferred tasks to be flushed".  
// Running 'thing3` by itself works fine though    
describe("stuff", function(){
    it('thing1', function(){
        // Test 1 code
    });
    it('thing2', function(){
        // Test 2 code 
    });
    it('thing3', function(){
        // Test 3 code
        $timeout.flush();  
    });
});

// Running like this also works fine, despite all the same code being run.
describe("stuff", function(){
    xit('thing1', function(){
        // Test 1 code
    });
    xit('thing2', function(){
        // Test 2 code 
    });
    it('thing3', function(){
        // Test 1 code
        // Test 2 code 
        // Test 3 code
        $timeout.flush();  
    });
});

Aucun commentaire:

Enregistrer un commentaire