|
| 1 | +import Double from '../../../src/value/double' |
| 2 | + |
| 3 | +let warnIfPromiseless, subject |
| 4 | +let double, type, outcomes, callback |
| 5 | +module.exports = { |
| 6 | + beforeEach: () => { |
| 7 | + warnIfPromiseless = td.replace('../../../src/when/warn-if-promiseless').default |
| 8 | + |
| 9 | + subject = require('../../../src/when/chain-stubbing').default |
| 10 | + |
| 11 | + // Common setup across tests: |
| 12 | + double = Double.create(null, null, null, () => 'a fake') |
| 13 | + callback = (t, o) => { type = t; outcomes = o } |
| 14 | + }, |
| 15 | + '.thenReturn': () => { |
| 16 | + const result = subject(double, callback).thenReturn(12, 23) |
| 17 | + |
| 18 | + assert.equal(result, 'a fake') |
| 19 | + assert.equal(type, 'thenReturn') |
| 20 | + assert.deepEqual(outcomes, [12, 23]) |
| 21 | + }, |
| 22 | + '.thenCallback': () => { |
| 23 | + const func = () => {} |
| 24 | + |
| 25 | + const result = subject(double, callback).thenCallback(func) |
| 26 | + |
| 27 | + assert.equal(result, 'a fake') |
| 28 | + assert.equal(type, 'thenCallback') |
| 29 | + assert.deepEqual(outcomes, [func]) |
| 30 | + }, |
| 31 | + '.thenDo': () => { |
| 32 | + const func = () => {} |
| 33 | + |
| 34 | + const result = subject(double, callback).thenDo(func) |
| 35 | + |
| 36 | + assert.equal(result, 'a fake') |
| 37 | + assert.equal(type, 'thenDo') |
| 38 | + assert.deepEqual(outcomes, [func]) |
| 39 | + }, |
| 40 | + '.thenThrow': () => { |
| 41 | + const error = new Error('hi') |
| 42 | + |
| 43 | + const result = subject(double, callback).thenThrow(error) |
| 44 | + |
| 45 | + assert.equal(result, 'a fake') |
| 46 | + assert.equal(type, 'thenThrow') |
| 47 | + assert.deepEqual(outcomes, [error]) |
| 48 | + }, |
| 49 | + '.thenResolve': () => { |
| 50 | + const result = subject(double, callback).thenResolve('pants') |
| 51 | + |
| 52 | + td.verify(warnIfPromiseless()) |
| 53 | + assert.equal(result, 'a fake') |
| 54 | + assert.equal(type, 'thenResolve') |
| 55 | + assert.deepEqual(outcomes, ['pants']) |
| 56 | + }, |
| 57 | + '.thenReject': () => { |
| 58 | + const error = new Error('hi') |
| 59 | + |
| 60 | + const result = subject(double, callback).thenReject(error) |
| 61 | + |
| 62 | + td.verify(warnIfPromiseless()) |
| 63 | + assert.equal(result, 'a fake') |
| 64 | + assert.equal(type, 'thenReject') |
| 65 | + assert.deepEqual(outcomes, [error]) |
| 66 | + } |
| 67 | +} |
0 commit comments