Skip to content

Commit 4064674

Browse files
committed
#rewrite wrap the when/* children
1 parent 23d073f commit 4064674

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
import _ from '../wrap/lodash'
2+
3+
import isCallback from '../matchers/is-callback'
4+
import callback from '../callback'
5+
16
export default function (type, args) {
7+
if (type === 'thenCallback' && !_.some(args, isCallback)) {
8+
return args.concat(callback)
9+
} else {
10+
return args
11+
}
212
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
let callback, isCallback, subject
12
module.exports = {
3+
beforeEach: () => {
4+
callback = td.replace('../../../src/callback').default
5+
isCallback = td.replace('../../../src/matchers/is-callback').default
26

7+
subject = require('../../../src/when/add-implied-callback-arg-if-necessary').default
8+
},
9+
'type is not thenCallback': () => {
10+
const result = subject('anything', [{}, 50])
11+
12+
assert.deepEqual(result, [{}, 50])
13+
},
14+
'type is thenCallback and no callback matcher is in the args': () => {
15+
td.when(isCallback(), {ignoreExtraArgs: true}).thenReturn(false)
16+
17+
const result = subject('thenCallback', [42, 'pants'])
18+
19+
assert.deepEqual(result, [42, 'pants', callback])
20+
},
21+
'type is thenCallback and a callback matcher IS in the args': () => {
22+
td.when(isCallback('a callback'), {ignoreExtraArgs: true}).thenReturn(true)
23+
24+
const result = subject('thenCallback', [42, 'pants', 'a callback'])
25+
26+
assert.deepEqual(result, [42, 'pants', 'a callback'])
27+
}
328
}

0 commit comments

Comments
 (0)