Skip to content

Commit 58d6644

Browse files
committed
Added full compatibility with Tape API:
- test function allows any params order - .skip and .only methods
1 parent f932932 commit 58d6644

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@
2929
"eslint": "^1.7.1",
3030
"faucet": "0.0.1",
3131
"tape": "^4.2.1"
32+
},
33+
"dependencies": {
34+
"object-assign": "^4.0.1"
3235
}
3336
}

src/index.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
export default function addAssertions (tape, assertions) {
2-
return (testName, testBody) => tape(testName, t => {
3-
for (let prop in assertions) {
4-
t[prop] = assertions[prop].bind(t);
5-
}
1+
import extend from 'object-assign';
62

7-
t.test = addAssertions(t.test, assertions);
3+
const addAssertions = (tape, assertions) => {
4+
const myTape = (...args) => {
5+
args = args.map(arg => {
6+
if (typeof arg === 'function') {
7+
return t => {
8+
Object.keys(assertions).forEach(assertName =>
9+
t[assertName] = assertions[assertName].bind(t)
10+
);
811

9-
testBody.call(t, t);
10-
});
11-
}
12+
t.test = addAssertions(t.test, assertions);
13+
14+
arg.call(t, t);
15+
};
16+
} else {
17+
return arg;
18+
}
19+
});
20+
tape(...args);
21+
};
22+
23+
return extend(myTape, tape);
24+
};
25+
26+
export default addAssertions;

tests/test.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const test = addAssertions(tape, {
1111
}
1212
});
1313

14-
test('New assertion definitions are available in the t instance', (t) => {
14+
test('New assertion definitions are available in the t instance', t => {
1515
t.different(1, 2);
1616
t.biggerThan(4, 5);
1717
t.end();
@@ -23,9 +23,25 @@ test('Can use destructuring with new assertions', ({biggerThan, end}) => {
2323
});
2424

2525
test('Subtests', (t) => {
26-
t.test('New assertions are available in subtests', (st) => {
26+
t.test('New assertions are available in subtests', st => {
2727
st.biggerThan(4, 5);
2828
st.end();
2929
});
3030
t.end();
31-
});
31+
});
32+
33+
test(t => {
34+
t.biggerThan(4, 5);
35+
t.end();
36+
}, 'Works with different params order');
37+
38+
test.skip('can skip tests', t => {
39+
t.fail();
40+
t.end();
41+
});
42+
43+
44+
test.skip('works with options', {skip: false}, t => {
45+
t.fail();
46+
t.end();
47+
});

0 commit comments

Comments
 (0)