Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-plugin-must-assert

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-plugin-must-assert - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

e2e/failing-jsdom/__tests__/index.js

2

package.json
{
"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 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc