Angular testing docs shows an test sample where $apply is called before testing assertions. I tried to do the same but my test is not working properly. The first code that should break, works... it seems that my assertion is not running. The second code, my test works but it's different from the documentation (which I like the style better).
First:
it('tests angular promises', function() {
getABC = function() {
return $q((resolve, reject) => {
resolve('abc');
});
};
var state = getABC()
$rootScope.$apply()
// assertions come after $apply call as in documentation: doesn't work.
state.should.eventually.be.equal('abcc')
})
------
✓ tests angular promises
1 passing (78ms)
Second
it('tests angular promises', function() {
getABC = function() {
return $q((resolve, reject) => {
resolve('abc');
});
};
var state = getABC()
state.should.eventually.be.equal('abcc')
// assertions come before $apply call: works
$rootScope.$apply()
})
------
1 failing
1) tests angular promises:
AssertionError: expected 'abc' to equal 'abcc'
+ expected - actual
-abc
+abcc