vendredi 30 octobre 2015

Jasmine unit testing $timeout (expect($timeout).toHaveBeenCalledWith(n);)

I would like to unit test an Angular.js $timeout to check that it has been called with the correct duration/delay value.

The assertion would look something like this:

expect($timeout).toHaveBeenCalledWith(n);

My Angular code looks roughly like the following:

$timeout(function() {
    // do something
}, attrs.timeout || 30000);

I want to ensure that without an override (attrs.timeout) it is called with 30000 and with the override it is called with that override.

I have tried a decorator like this:

// from: http://ift.tt/1PZ07GB
beforeEach(module(function($provide) {
    $provide.decorator('$timeout', function($delegate) {
        return jasmine.createSpy($delegate);
    });
}));

Plus several other methods but I cannot seem to get it to work.

I am using Angular 1.3.20, Jasmine 2.3.4

Any suggestions gratefully received.

Aucun commentaire:

Enregistrer un commentaire