Skip to content

Commit 2054c80

Browse files
committed
test config & log
1 parent ff8eae1 commit 2054c80

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

test/support/custom-assertions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ export default function customAssertions (assert) {
22
assert.deepEqualSet = (actual, expected) => {
33
assert.deepEqual(Array.from(actual), expected)
44
}
5+
6+
assert.doesntThrow = (func) => {
7+
func()
8+
}
59
}

test/unit/config.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
let log, subject
2+
module.exports = {
3+
beforeEach: () => {
4+
log = td.replace('../../src/log').default
5+
6+
subject = require('../../src/config').default
7+
},
8+
'defaults': () => {
9+
const result = subject()
10+
11+
assert.deepEqual(result, {
12+
ignoreWarnings: false,
13+
promiseConstructor: global.Promise,
14+
suppressErrors: false
15+
})
16+
},
17+
'overriding an actual property': () => {
18+
const result = subject({ignoreWarnings: true})
19+
20+
assert.equal(result.ignoreWarnings, true)
21+
assert.equal(subject().ignoreWarnings, true)
22+
},
23+
'overriding a deprecated property': () => {
24+
const result = subject({extendWhenReplacingConstructors: true})
25+
26+
assert.equal(result.extendWhenReplacingConstructors, undefined)
27+
assert.equal(subject().extendWhenReplacingConstructors, undefined)
28+
td.verify(log.warn('td.config',
29+
'"extendWhenReplacingConstructors" is no longer a valid configuration key. Remove it from your calls to td.config() or it may throw an error in the future. For more information, try hunting around our GitHub repo for it:\n\n https://github.com/testdouble/testdouble.js/search?q=extendWhenReplacingConstructors'
30+
))
31+
},
32+
'overriding a non-existent property': () => {
33+
subject({wat: 'wat?'})
34+
35+
td.verify(log.error('td.config',
36+
'"wat" is not a valid configuration ' +
37+
'key (valid keys are: ["ignoreWarnings", ' +
38+
'"promiseConstructor", "suppressErrors"])'))
39+
}
40+
}

test/unit/log.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
let config, subject, consoleWarn
2+
module.exports = {
3+
beforeEach: () => {
4+
consoleWarn = td.replace(console, 'warn')
5+
config = td.replace('../../src/config').default
6+
7+
subject = require('../../src/log').default
8+
},
9+
'.warn': {
10+
'not ignoring warnings': () => {
11+
td.when(config()).thenReturn({ignoreWarnings: false})
12+
13+
subject.warn('aFunc', 'a message', 'http://url')
14+
15+
td.verify(console.warn('Warning: testdouble.js - aFunc - a message (see: http://url )'))
16+
},
17+
'ignoring warnings': () => {
18+
td.when(config()).thenReturn({ignoreWarnings: true})
19+
20+
subject.warn('aFunc', 'a message', 'http://url')
21+
22+
assert.equal(td.explain(console.warn).callCount, 0)
23+
}
24+
},
25+
'.error': {
26+
'not suppressing errors': () => {
27+
td.when(config()).thenReturn({suppressErrors: false})
28+
29+
assert.throws(() => {
30+
subject.error('aFunc', 'a message', 'http://url')
31+
}, /Error\: testdouble\.js \- aFunc \- a message \(see\: http\:\/\/url \)/)
32+
},
33+
'suppressing errors': () => {
34+
td.when(config()).thenReturn({suppressErrors: true})
35+
36+
assert.doesntThrow(() => {
37+
subject.error('aFunc', 'a message', 'http://url')
38+
})
39+
}
40+
},
41+
'.fail just blows up': () => {
42+
assert.throws(() => {
43+
subject.fail('Just boom')
44+
}, /Just boom/)
45+
}
46+
}

0 commit comments

Comments
 (0)