Helps write adhesive tape tests and better organize your test code.
var scotchTape = require('scotch-tape');
var test = scotchTape({options});
setup
- Optional - called before any tests starts runningbefore
- Optional -called before every test runafter
- Optional -called after every test runteardown
- Optional -called after all the tests are runasserts
- Optional - custom local assertions
'use strict';
var scotchTape = require('scotch-tape');
var test = scotchTape({
setup: function initialize(t) {
console.log('setup');
t.end();
},
before: function beforeEach(t) {
console.log('Before Each');
t.end();
},
after: function afterEach(t) {
console.log('After Each');
t.end();
},
teardown: function cleanup(t) {
console.log('teardown');
t.end();
},
asserts: {
isValidName: function customAssert(name) {
this.ok(name);
this.equal(name, 'test');
}
/* any number of custom local asserts*/
}
});
test('scotch-tape tests', function test(it) {
it('should get called', function should(t) {
t.ok(true);
t.end();
});
it('should support custom assert', function should(t) {
t.isValidName('test');
t.end();
});
});
TAP version 13
# setup
setup
# Project Tests > should pass 1
Before Each
ok 1 (unnamed assert)
After Each
# Project Tests > should pass 2
Before Each
ok 2 (unnamed assert)
After Each
# teardown
teardown
1..2
# tests 2
# pass 2
# ok
You can overload tape js tests to include custom assertions.
'use strict';
var scotchTapeAsserts = require('scotch-tape/asserts');
var scotchTape = scotchTapeAsserts({
typeOf: function verifyType(obj, type) {
this.equal(typeof obj, type);
},
length: function verifyLength(obj, len) {
this.equal(obj.length, len);
}
});
var runBasicTests = scotchTape();
runBasicTests('Global Tape Asserts', function test(it) {
it('should handle type', function should(t) {
var a = 'segu';
t.typeOf(a, 'string');
t.end();
});
it('should handle length', function should(t) {
var a = [1, 2, 3, 4];
t.length(a, 4);
t.end();
});
});
TAP version 13
# Global Tape Asserts > should handle type
ok 1 should be equal
# Global Tape Asserts > should handle length
ok 2 should be equal
1..2
# tests 2
# pass 2
# ok
ENJOY WRITING BETTER TESTS