Angular testing docs は、アサーションをテストする前に $apply が呼び出されるテスト サンプルを示しています。同じことをしようとしましたが、テストが正しく機能していません。壊れるはずの最初のコードが機能します...私のアサーションが実行されていないようです。2 番目のコード、私のテストは機能しますが、ドキュメントとは異なります (スタイルの方が好きです)。
初め:
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)
2番
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