jest-plugin-must-assert
Advanced tools
Comparing version 1.5.0 to 1.6.0
{ | ||
"name": "jest-plugin-must-assert", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Jest plugin for async tests", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,5 +25,30 @@ # `jest-plugin-must-assert` | ||
## Supported Jest Environments | ||
- `jest-plugin-must-assert` - Default supported environment, `node` | ||
- `jest-plugin-must-assert/jsdom` - JSDOM environment support. Necessary for | ||
mocking window task functions like `setTimeout` when using `jest-environment-jsdom`. | ||
Useful for React tests. | ||
## Use | ||
### For a specific test file | ||
You may import the plugin into any test file you need additional safeguard for async logic. | ||
```js | ||
import 'jest-plugin-must-assert'; | ||
test('some logic', () => { | ||
setTimeout(() => expect(1).toBe(2)); // will be caught by the plugin | ||
... | ||
}); | ||
``` | ||
### For entire test suite | ||
Alternatively, you can enable the plugin for an entire test suite by adding it | ||
to your jest configuration. | ||
```js | ||
... | ||
@@ -34,2 +59,4 @@ setupFilesAfterEnv: ['jest-plugin-must-assert'], | ||
### Manual configuration | ||
You may also extend the default behavior with the following, manual configuration. | ||
@@ -36,0 +63,0 @@ |
const runJest = require('../runJest'); | ||
// A generous timeout as the e2e failing tests timeout in some cases (as intended) | ||
jest.setTimeout(8000); | ||
jest.setTimeout(10000); | ||
test('failing tests', async () => { | ||
test('failing tests - node env', async () => { | ||
const results = await runJest('e2e/failing'); | ||
@@ -17,2 +17,13 @@ | ||
test('failing tests - jsdom env', async () => { | ||
const results = await runJest('e2e/failing-jsdom'); | ||
const totalTestsExecuted = | ||
results.json.numTotalTests - results.json.numPendingTests; | ||
// We should have ran _some_ tets here | ||
expect(totalTestsExecuted > 0).toBe(true); | ||
// All tests that were executed should have failed | ||
expect(results.json.numFailedTests).toBe(totalTestsExecuted); | ||
}); | ||
test('passing tests', async () => { | ||
@@ -22,3 +33,4 @@ const results = await runJest('e2e/passing'); | ||
const totalTestsExecuted = | ||
results.json.numTotalTests - results.json.numPendingTests; | ||
results.json.numTotalTests - | ||
(results.json.numPendingTests + results.json.numTodoTests); | ||
// We should have ran _some_ tets here | ||
@@ -25,0 +37,0 @@ expect(totalTestsExecuted > 0).toBe(true); |
@@ -7,4 +7,11 @@ /** | ||
const [env = 'node'] = process.argv.slice(2); | ||
const projectmap = { | ||
node: './e2e/failing', | ||
jsdom: './e2e/failing-jsdom', | ||
passing: './e2e/passing', | ||
}; | ||
const options = { | ||
projects: ['./e2e/failing'], | ||
projects: [projectmap[env]], | ||
watch: true, | ||
@@ -11,0 +18,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20578
17
508
127