각진 앱에 대한 단위 테스트를 작성하는 중 예기치 않은 결과가 발생했습니다. 예기치 않은 행동을 샘플 테스트로 응축 할 수있었습니다.실패한 어설 션이 약속 잡기를 유발하는 이유는 무엇입니까?
그 다음 블록에서 should.equal(true, false, 'should then')
어설 션 오류는 약속의 catch 블록을 트리거하는 것으로 보입니다. 나는이 테스트를 실행하면
describe.only('test', function() {
var $q, $rootScope;
beforeEach(function() {
inject(function(_$q_, _$rootScope_) {
$q = _$q_;
$rootScope = _$rootScope_.$new();
});
});
var stubService = sinon.stub(service, 'getPanel');
it('shall...', function() {
//1
$q.when().then(function() {
console.log('log then')
should.equal(true, false, 'should then') //<---assertion fails
}).catch(function() {
console.log('log catch') //<--- why does this block run?
should.equal(true, false, 'should catch')
})
$rootScope.$apply(); //wait for promises to finish
});
});
출력은 다음과 같습니다
LOG LOG: 'log then'
LOG LOG: 'log catch'
test
✗ shall...
should catch: expected true to equal false
내가 예상 :
LOG LOG: 'log then'
test
✗ shall...
should then: expected true to equal false
내가 예상 결과를 얻을이 스타일을 사용하는 경우 :
$q.when().then(function() {
console.log('log then')
should.equal(true, false, 'should then')
}, function() {
console.log('log catch')
should.equal(true, false, 'should catch')
})
을
우리 회사의 관례는 전나무 t 스타일을 사용하므로 가능한 경우 첫 번째 스타일을 사용하고 싶습니다.