-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
39 lines (30 loc) · 1.02 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const pitesti = require('pitesti')
const tage = require('./index')
const { strictEqual: equal } = require('assert')
const test = pitesti()
function testFn (str, arg1, arg2) {
return [str, arg1, arg2, this].join(' ')
}
const wrapped = tage(testFn)
const topThis = (function () { return this })()
const bop = {
toString: () => 'bop',
wrapped
}
const ordinaryArray = Object.assign([], { toString: () => '[arr]' })
test`function works as normal`(() => {
equal(wrapped('foo', 'bar', 'baz'), 'foo bar baz ' + topThis)
})
test`function works as normal with context`(() => {
equal(bop.wrapped('foo', 'bar', 'baz'), 'foo bar baz bop')
})
test`function works with template string`(() => {
equal(wrapped`foo`('bar', 'baz'), 'foo bar baz ' + topThis)
})
test`function works with template string with context`(() => {
equal(bop.wrapped`foo`('bar', 'baz'), 'foo bar baz bop')
})
test`function does not assume tagged for ordinary array 1st arg`(() => {
equal(wrapped(ordinaryArray, 'foo', 'bar'), '[arr] foo bar ' + topThis)
})
test()