Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Just Use Tape
import test from 'tape';
const before = test;
const after = test;
// beforeEach/afterEach rely on shared state.
// That's a big anti-pattern for testing.
// It's also silly to run something before and after
// ever test -- many of your tests won't need it.
// Try this, instead:
const setup = () => {
const fixtures = {};
// Insert your fixture code here.
// Make sure you're creating fresh objects each
// time setup() is called.
return fixtures;
};
const teardown = (fixtures) => {
// Dispose of your fixtures here.
};
before('before', function (assert) {
assert.pass('Do something before tests here');
assert.end();
});
test('A test with fixtures', (assert) => {
const fixture = setup();
assert.equal(typeof fixture, 'object',
'fixture should return an object');
teardown(fixture);
assert.end();
});
test('A passing test', (assert) => {
assert.pass('This test will pass.');
assert.end();
});
test('Assertions with tape.', (assert) => {
const expected = 'something to test';
const actual = 'sonething to test';
assert.equal(actual, expected,
'Given two mismatched values, .equal() should produce a nice bug report');
assert.end();
});
after('after', (assert) => {
assert.pass('Do something after tests here.');
assert.end();
});
@tomByrer

This comment has been minimized.

Copy link

@tomByrer tomByrer commented Aug 24, 2015

Minor typo:
// everY test

@rualatngua

This comment has been minimized.

Copy link

@rualatngua rualatngua commented Jun 12, 2016

@ericelliott
In my case, My fixtures is setup PostgreSQL data, should I add a callback function in setup() method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.