All Projects → airbnb → mocha-wrap

airbnb / mocha-wrap

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mocha-wrap

jest-wrap
Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Jest tests.
Stars: ✭ 35 (-35.19%)
Mutual labels:  mocha, testing-tools, javascript-tests, mocha-wrap
playwright-test
Run unit tests with several runners or benchmark inside real browsers with playwright.
Stars: ✭ 81 (+50%)
Mutual labels:  mocha, tests, testing-tools
Telegraf-Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Stars: ✭ 22 (-59.26%)
Mutual labels:  mocha, tests, testing-tools
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+64983.33%)
Mutual labels:  tests, testing-tools, javascript-tests
cucumber-steps
🥒 Quick start for testing with Cucumber.js
Stars: ✭ 15 (-72.22%)
Mutual labels:  mocha, testing-tools
tic-tac-toe-game-using-bit
Simple Tic Tac Toe game built with react-typescript components
Stars: ✭ 19 (-64.81%)
Mutual labels:  mocha, mocha-tests
spectron-typescript-starter
Spectron TypeScript Starter for e2e testing electron applications
Stars: ✭ 15 (-72.22%)
Mutual labels:  mocha, tests
Mocha
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+38762.96%)
Mutual labels:  mocha, testing-tools
Atom Mocha Test Runner
Run your Atom package tests using Mocha
Stars: ✭ 10 (-81.48%)
Mutual labels:  mocha, tests
PixelTest
Fast, modern, simple iOS snapshot testing written purely in Swift.
Stars: ✭ 56 (+3.7%)
Mutual labels:  tests, testing-tools
Ts Mocha
Mocha thin wrapper that allows running TypeScript tests with TypeScript runtime (ts-node) to get rid of compilation complexity
Stars: ✭ 119 (+120.37%)
Mutual labels:  mocha, testing-tools
Teaspoon
Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
Stars: ✭ 1,443 (+2572.22%)
Mutual labels:  mocha, javascript-tests
Testdeck
Object oriented testing
Stars: ✭ 206 (+281.48%)
Mutual labels:  mocha, testing-tools
BotBlock.org
BotBlock - The List of Discord Bot Lists and Services
Stars: ✭ 29 (-46.3%)
Mutual labels:  mocha, mocha-tests
react-native-unit-tests
Example how to test React Native components
Stars: ✭ 79 (+46.3%)
Mutual labels:  mocha, testing-tools
givens
Easy test setup without side effects.
Stars: ✭ 22 (-59.26%)
Mutual labels:  mocha, javascript-tests
Approvals.NodeJS
Approval Tests implementation in NodeJS
Stars: ✭ 79 (+46.3%)
Mutual labels:  mocha, testing-tools
Mongodb Memory Server
Spinning up mongod in memory for fast tests. If you run tests in parallel this lib helps to spin up dedicated mongodb servers for every test file in MacOS, *nix, Windows or CI environments (in most cases with zero-config).
Stars: ✭ 1,376 (+2448.15%)
Mutual labels:  tests, testing-tools
Acutest
Simple header-only C/C++ unit testing facility.
Stars: ✭ 170 (+214.81%)
Mutual labels:  tests, testing-tools
Suman
🌇 🌆 🌉 Advanced, user-friendly, language-agnostic, super-high-performance test runner. http://sumanjs.org
Stars: ✭ 57 (+5.56%)
Mutual labels:  mocha, testing-tools

mocha-wrap Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

Fluent pluggable interface for easily wrapping describe, context, it, and specify blocks in Mocha tests.

Example

var wrap = require('mocha-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 mocha-wrap plugin is a named function that returns a MochaWrapper 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 mocha 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 MochaWrapper.

  • 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 mocha beforeEach function

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

  • before: a function, or array of functions, for use in a mocha before function

  • after: a function, or array of functions, for use in a mocha after 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 MochaWrapper instance.

To register a plugin, call the register function on mocha-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
			}
		],
		before: function () {
			// setup ran once before all tests
		},
		after: function () {
			// teardown ran once after all tests
		}
	});
};

Usage

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

wrap().withFoo().describe…

skip/only

Although mocha has describe.skip, describe.only, context.skip, context.only, it.skip, it.only, specify.skip, and specify.only, it is not possible to implement these in mocha-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].