All Projects → airbnb → jest-wrap

airbnb / jest-wrap

Licence: MIT License
Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Jest tests.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to jest-wrap

mocha-wrap
Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Mocha tests.
Stars: ✭ 54 (+54.29%)
Mutual labels:  mocha, testing-tools, javascript-tests, mocha-wrap
Testdeck
Object oriented testing
Stars: ✭ 206 (+488.57%)
Mutual labels:  mocha, jest, testing-tools
givens
Easy test setup without side effects.
Stars: ✭ 22 (-37.14%)
Mutual labels:  mocha, javascript-tests, jest-tests
Approvals.NodeJS
Approval Tests implementation in NodeJS
Stars: ✭ 79 (+125.71%)
Mutual labels:  mocha, testing-tools
tropic
🍍 Test Runner Library
Stars: ✭ 29 (-17.14%)
Mutual labels:  mocha, jest
react-native-unit-tests
Example how to test React Native components
Stars: ✭ 79 (+125.71%)
Mutual labels:  mocha, testing-tools
Root Cause
🔍 Root Cause is a tool for troubleshooting Puppeteer and Playwright tests. 🔎
Stars: ✭ 205 (+485.71%)
Mutual labels:  mocha, jest
Telegraf-Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Stars: ✭ 22 (-37.14%)
Mutual labels:  mocha, testing-tools
playwright-test
Run unit tests with several runners or benchmark inside real browsers with playwright.
Stars: ✭ 81 (+131.43%)
Mutual labels:  mocha, testing-tools
qa-automation-base
There are basic projects for automation frameworks based on Kotlin/Java and TypeScript for the backend, frontend, and mobile.
Stars: ✭ 45 (+28.57%)
Mutual labels:  mocha, jest
xv
❌ ✔️ zero-config test runner for simple projects
Stars: ✭ 588 (+1580%)
Mutual labels:  mocha, jest
Nodebestpractices
✅ The Node.js best practices list (December 2021)
Stars: ✭ 72,734 (+207711.43%)
Mutual labels:  mocha, jest
Babel Plugin Tester
Utilities for testing babel plugins
Stars: ✭ 228 (+551.43%)
Mutual labels:  mocha, jest
patent-free-react-ecosystem-migration-plan
Patent Free React Ecosystem Migration Plan
Stars: ✭ 15 (-57.14%)
Mutual labels:  mocha, jest
cucumber-steps
🥒 Quick start for testing with Cucumber.js
Stars: ✭ 15 (-57.14%)
Mutual labels:  mocha, testing-tools
eslint-config-adjunct
A reasonable collection of plugins to use alongside your main esLint configuration
Stars: ✭ 39 (+11.43%)
Mutual labels:  mocha, jest
Snap Shot
Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
Stars: ✭ 170 (+385.71%)
Mutual labels:  mocha, jest
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (+405.71%)
Mutual labels:  mocha, jest
wily
Build Node.js APIs from the command line (Dead Project 😵)
Stars: ✭ 14 (-60%)
Mutual labels:  mocha, jest
react-multi-context
Manage multiple React 16 contexts with a single component.
Stars: ✭ 19 (-45.71%)
Mutual labels:  mocha, jest

jest-wrap Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

Fluent pluggable interface for easily wrapping describe, it, and test blocks in Jest tests.

Example

var wrap = require('jest-wrap');
var expect = require('chai').expect;

var mockWindow = {
	location: {
		href: 'test/url'
	}
};
wrap().withGlobal('window', () => mockWindow).describe('mocked window', function () {
	it('is mocked', function () {
		expect(window).to.equal(mockWindow);
	});

	it('has the right URL', function () {
		expect(window.location.href).to.equal('test/url');
	});
});

var obj = { a: 1 };
wrap().withOverrides(() => obj, () => ({ a: 2, b: 3 })).describe('overridden object keys', function () {
	it('has "b"', function () {
		expect(obj.b).to.equal(3);
	});

	it('has overridden "a"', function () {
		expect(obj.a).to.equal(2);
	});
});

wrap().withOverride(() => obj, 'a', () => 4).skip().describe('this test is skipped', function () {
	it('also supports .only()!', function () {
		expect(true).to.equal(false); // skipped
	});
});

Plugins

A jest-wrap plugin is a named function that returns a JestWrapper instance or a descriptor object.

  • A plugin’s function name must begin with the string “with”.

  • Plugins can be globally registered, or .used ad-hoc.

  • .use requires a plugin function as its first argument; further arguments are passed through to the plugin.

  • .extend requires a non-empty description string, and a descriptor object which may contain a value that is a function, or an array of functions, whose keys correspond to any or all of the supported jest methods.

  • Globally registered plugins, .use calls, and .extend calls can be chained, stored, and reused - each link in the chain creates a new instance of a JestWrapper.

  • A descriptor object may contain any or all of these 5 keys:

  • a description string, for use in “describe” and/or “it” (this is required when returning an object)

  • beforeEach: a function, or array of functions, for use in a jest beforeEach function

  • afterEach: a function, or array of functions, for use in a jest afterEach function

  • beforeAll: a function, or array of functions, for use in a jest beforeAll function

  • afterAll: a function, or array of functions, for use in a jest afterAll function

The most common approach will be for a plugin function to return this.extend(description, descriptor).

A plugin function must have a name that starts with “with”, and will be invoked with a receiver (”this” value) of a JestWrapper instance.

To register a plugin, call the register function on jest-wrap with the plugin function. This should not be done in a reusable module.

module.exports = function withFoo(any, args, you, want) {
	return this.extend('with some foo stuff', {
		beforeEach: function () {
			// setup ran before each test
		},
		afterEach: [
			function () {
				// teardown ran after each test
			},
			function () {
				// more teardown
			}
		],
		beforeAll: function () {
			// setup ran once before all tests
		},
		afterAll: function () {
			// teardown ran once after all tests
		}
	});
};

Usage

var wrap = require('jest-wrap');
wrap.register(require('jest-wrap-with-foo'));

wrap().withFoo().describe…

skip/only

Although jest has describe.skip, describe.only, it.skip, it.only, test.skip, and test.only, it is not possible to implement these in jest-wrap without using ES5 property accessors. Since this project supports ES3, we decided to use .skip().describe etc rather than forfeit the ability to have skip/only.

Tests

Simply clone the repo, npm install, and run npm test

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].