-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathacceptance.js
81 lines (69 loc) · 2.54 KB
/
acceptance.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import inspect from '../lib/index.js'
import { expect } from 'chai'
describe('arrays', () => {
it('truncates an array of strings rather than just the strings', () => {
expect(inspect(['foo', 'bar', 'baz', 'bing'], { truncate: 22 })).to.equal("[ 'foo', 'bar', …(2) ]")
})
it('truncates the string in certain cases, to keep under the truncate threshold', () => {
expect(inspect(['foobarbazbing'], { truncate: 15 })).to.equal("[ 'foobarba…' ]")
})
})
describe('objects', () => {
it('correctly inspects Symbols as object keys', () => {
expect(inspect({ [Symbol('foo')]: 1 })).to.equal('{ [Symbol(foo)]: 1 }')
})
it('correctly inspects properties and Symbols as object keys', () => {
expect(inspect({ foo: 1, [Symbol('foo')]: 1 })).to.equal('{ foo: 1, [Symbol(foo)]: 1 }')
})
it('does not use custom inspect functions if `customInspect` is turned off', () => {
const obj = {
inspect: () => 1,
}
expect(inspect(obj, { customInspect: false })).to.equal('{ inspect: [Function inspect] }')
})
it('uses custom inspect function is `customInspect` is turned on', () => {
const obj = {
inspect: () => 1,
}
expect(inspect(obj, { customInspect: true })).to.equal('1')
})
it('does not use custom inspect functions if `customInspect` is turned off', () => {
const obj = {
inspect: () => 1,
}
expect(inspect(obj, { customInspect: false })).to.equal('{ inspect: [Function inspect] }')
})
it('uses custom inspect function if `customInspect` is turned on', () => {
const obj = {
inspect: () => 'abc',
}
expect(inspect(obj, { customInspect: true })).to.equal('abc')
})
it('inspects custom inspect function result', () => {
const obj = {
inspect: () => ['foobarbazbing'],
}
expect(inspect(obj, { customInspect: true, truncate: 15 })).to.equal("[ 'foobarba…' ]")
})
it('uses a custom deeply nested inspect function if `customInspect` is turned on', () => {
const obj = {
sub: {
inspect: (depth, options) => options.stylize('Object content', 'string'),
},
}
expect(inspect(obj, { customInspect: true })).to.equal('{ sub: Object content }')
})
it('inspect with custom object-returning inspect', () => {
const obj = {
sub: {
inspect: () => ({ foo: 'bar' }),
},
}
expect(inspect(obj, { customInspect: true })).to.equal("{ sub: { foo: 'bar' } }")
})
})
describe('arrays', () => {
it('can contain anonymous functions', () => {
expect(inspect([() => 1])).to.equal('[ [Function] ]')
})
})