I have sequential and complicated test scenarios, where there was no point to continue test suit if one of tests of this suite failed. But I have not managed to mark them as skipped, so they are shown as passed.
example of my test suite:
describe('Test scenario 1', () => {
test('that item can be created', async () => {
expect(true).toBe(false)
})
test('that item can be deleted', async () => {
...
})
...
which I changed to the following:
let hasTestFailed = false
const sequentialTest = (name, action) => {
test(name, async () => {
if(hasTestFailed){
console.warn(`[skipped]: ${name}`)}
else {
try {
await action()}
catch (error) {
hasTestFailed = true
throw error}
}
})
}
describe('Test scenario 1', () => {
sequentialTest('that item can be created', async () => {
expect(true).toBe(false)
})
sequentialTest('that item can be deleted', async () => {
...
})
If the first test will fail, the next tests won’t run, but they will get status Passed.
The report will look like:
- Test scenario 1 > that item can be created – Failed
- Test scenario 1 > that item can be deleted – Passed
That is not ideal, but acceptable in my case since I want to see only failed tests in my reports.