Ответ 1
Вы можете использовать this.currentTest.state
(не уверен, когда это было введено):
afterEach(function() {
if (this.currentTest.state === 'failed') {
// ...
}
});
Я пытаюсь создать hooked afterEach с логикой, которая должна срабатывать только при предыдущем тесте. Например:
it("some_test1", function(){
// something that could fail
})
it("some_test2", function(){
// something that could fail
})
afterEach(function(){
if (some_test_failed) {
// do something to respond to the failing test
} else {
// do nothing and continue to next test
}
})
Однако, я не знаю, как определить, не удалось ли выполнить тест из hook. Есть ли какой-нибудь прослушиватель событий, который я могу подключить к мокко? Может быть, что-то вроде этого:
myTests.on("error", function(){ /* ... */ })
Вы можете использовать this.currentTest.state
(не уверен, когда это было введено):
afterEach(function() {
if (this.currentTest.state === 'failed') {
// ...
}
});
Вы можете сделать следующее
describe('something', function(){
var ok = true;
it('should one', function(){
ok = true;
})
it('should two', function(){
// say the test fails here
ok = false;
})
afterEach(function(){
if (!ok) this.test.error(new Error('something went wrong'));
})
})