0
角測試文檔顯示了一個test sample其中$敷在測試之前斷言叫。我試圖做同樣的事情,但我的測試工作不正常。第一個應該打破的代碼,工作......似乎我的斷言沒有運行。第二個代碼,我的測試工作,但它不同於文檔(我更喜歡這種風格)。
第一:
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)
二
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