-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add tests for failed mocha hooks
- Loading branch information
1 parent
1471a17
commit baf3519
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
spec: '**/*.test.js' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
const { strictEqual } = require('node:assert'); | ||
|
||
describe('with beforeAll hook', () => { | ||
before(() => { | ||
console.log('Before hook executed once!'); | ||
}); | ||
|
||
it('addition', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with beforeEach hook', () => { | ||
beforeEach(() => { | ||
console.log('BeforeEach hook executed every time!'); | ||
}); | ||
|
||
it('addition', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with broken before hook (suite must be failed)', () => { | ||
before(() => { | ||
throw new Error('Before hook is broken!!!'); | ||
}); | ||
|
||
it('addition (skipped)', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction (skipped)', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing (skipped)', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with broken beforeEach hook (suite must be failed)', () => { | ||
beforeEach(() => { | ||
throw new Error('BeforeEach hook is broken!!!'); | ||
}); | ||
|
||
it('addition (skipped)', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction (skipped)', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing (skipped)', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with broken after hook (suite must be failed)', () => { | ||
after(() => { | ||
throw new Error('After hook is broken!!!'); | ||
}); | ||
|
||
it('addition', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with broken afterEach hook (suite must be failed)', () => { | ||
afterEach(() => { | ||
throw new Error('After each hook is broken!!!'); | ||
}); | ||
|
||
it('addition (success)', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction (skipped)', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing (skipped)', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); |