|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var tape = require('../'); |
| 4 | +var tap = require('tap'); |
| 5 | +var concat = require('concat-stream'); |
| 6 | + |
| 7 | +var stripFullStack = require('./common').stripFullStack; |
| 8 | + |
| 9 | +tap.test('using a custom assertion', function (tt) { |
| 10 | + tt.plan(1); |
| 11 | + |
| 12 | + var test = tape.createHarness(); |
| 13 | + var count = 0; |
| 14 | + test.createStream().pipe(concat(function (body) { |
| 15 | + tt.same(stripFullStack(body.toString('utf8')), [].concat( |
| 16 | + 'TAP version 13', |
| 17 | + '# with a custom assertion', |
| 18 | + 'ok ' + ++count + ' true is ok', |
| 19 | + 'ok ' + ++count + ' value must be the answer to life, the universe, and everything', |
| 20 | + 'ok ' + ++count + ' what is 6 * 9?', |
| 21 | + 'not ok ' + ++count + ' what is 6 * 9!', |
| 22 | + ' ---', |
| 23 | + ' operator: equal', |
| 24 | + ' expected: 42', |
| 25 | + ' actual: 54', |
| 26 | + ' at: Test.isAnswer ($TEST/assertion.js:$LINE:$COL)', |
| 27 | + ' stack: |-', |
| 28 | + ' Error: what is 6 * 9!', |
| 29 | + ' [... stack stripped ...]', |
| 30 | + ' at Test.isAnswer ($TEST/assertion.js:$LINE:$COL)', |
| 31 | + ' [... stack stripped ...]', |
| 32 | + ' at Test.<anonymous> ($TEST/assertion.js:$LINE:$COL)', |
| 33 | + ' [... stack stripped ...]', |
| 34 | + ' ...', |
| 35 | + '', |
| 36 | + '1..' + count, |
| 37 | + '# tests ' + count, |
| 38 | + '# pass ' + (count - 1), |
| 39 | + '# fail 1', |
| 40 | + '' |
| 41 | + )); |
| 42 | + })); |
| 43 | + |
| 44 | + var isAnswer = function (value, msg) { |
| 45 | + // eslint-disable-next-line no-invalid-this |
| 46 | + this.equal(value, 42, msg || 'value must be the answer to life, the universe, and everything'); |
| 47 | + }; |
| 48 | + |
| 49 | + test('with a custom assertion', function (t) { |
| 50 | + t.ok(true, 'true is ok'); |
| 51 | + t.assertion(isAnswer, 42); |
| 52 | + t.assertion(isAnswer, 42, 'what is 6 * 9?'); |
| 53 | + t.assertion(isAnswer, 54, 'what is 6 * 9!'); |
| 54 | + |
| 55 | + t.end(); |
| 56 | + }); |
| 57 | +}); |
0 commit comments