Skip to content

robcatch/mocha-filter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mocha Filter

This package allows you to add custom filters to the various test stages in the Mocha test framework.

By default (when you require('mocha-filter')) an ignore filter is added, which will completely remove a test (or set of tests) from the test run without leaving a trace in the test output.

Examples

The filters can be used to restrict test runs to only be used when in specific environments:

var filter = require('mocha-filter');

filter.addFilter('preprod', () => {
	return _config.test_env === 'pre-production';
});

describe.preprod('A test set which should only run in pre-production', () => {
	//...
});

So long as the supplied function for the filter returns a boolean value, you can make it execute whatever you would like, without having to wrap tests in conditionals

filter.addFilter('dataSupplied', () => {
	if (!_config.sample_data) {
		console.error('Error: data not supplied. Skipping test.');
		return false;
	}
	return true;
});

describe('Example tests', () => {
	it.dataSupplied('Test to only run when sample data is supplied', done => {
		//...
		done();
	});
})

About

Util for adding custom filters to Mocha

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%