Because JS unit testing shouldn't be complicated.
Features
- A dead-simple setup because you just want to test your code.
- Familiar test definition methods because they make sense.
- Plain assertion methods because code.is.not.text.
- Predictable naming because you're tired of looking at docs.
- ES5 support because you're not always babelifying everything.
- Browser and node support because your project could be anything.
- Concise output with diffs because you just want to see what went wrong.
- Global, require, and import support because that part is up to you.
- Baked in performance testing because perf matters.
Install
npm install ready-test
Browser
To get up and running in the browser, link the included CSS/JS:
<html>
<head>
*<link rel="stylesheet" href="node_modules/ready-test/ready-test.css">*
</head>
<body>
*<script src="node_modules/ready-test/ready-test.js"></script>*
</body>
</html>
Then link your source files and tests:
<html>
<head>
<link rel="stylesheet" href="node_modules/ready-test/ready-test.css">
</head>
<body>
<script src="node_modules/ready-test/ready-test.js"></script>
*<script src="src/user.js"></script>*
*<script src="test/userTest.js"></script>*
</body>
</html>
The tests will run and output in the browser:
Node
In node, simply execute the script provided:
> npx ready-test
Or in npm versions below 5.2.0:
> ./node_modules/.bin/ready-test
The tests will run and output in the console:
By default the runner will find tests like
test/userTest.js
,
test/tests/user.js
,
spec/userSpec.js
spec/specs/user.js
etc.
You can also add it to your
package.json
file to run with
npm test
:
"scripts": {
"test": "ready-test"
}
Usage
- Define tests with familiar describe and it blocks:
*describe('User', () => {*
*it('should save', () => {*
assertTrue(user.save());
assertEqual(user.id, id);
*});*
*});*
- Test your code with readable assertion methods:
it('should save', () => {
*assertTrue(user.save());*
*assertEqual(user.id, id);*
});
- Focus or skip tests or suites with a single character:
*fit*('Focused test', () => {
*xit*('Skipped test', () => {
*fdescribe*('Focused suite', () => {
*xdescribe*('Skipped suite', () => {
- Return a promise to wait for code to run:
it('should save', () => {
*return user.save().then(() => {*
assertEqual(user.id, id);
*});*
});
- Or with async/await:
it('should save', *async* () => {
*await user.save();*
assertEqual(user.id, id);
});
- Run support code with standard before/after methods:
*beforeEach*(() => ...
*afterEach*(() => ...
*beforeAll*(() => ...
*afterAll*(() => ...
Other Features
- All code blocks run synchronously unless they return a promise.
- Easy browser configuration with data attributes.
- Nestable suites to help organize your tests.
- Fold mode to output nesting at different levels of detail.
- Runner watches directories and re-runs tests in node.
- Test randomization and features to help track down race conditions.
- Older IE support with polyfills.
- Custom assertions.