test: add tests for deprecate.property()
This commit is contained in:
parent
0a614217ce
commit
61fac1bbc1
1 changed files with 24 additions and 0 deletions
|
@ -49,6 +49,30 @@ describe('deprecations', () => {
|
|||
assert.equal(typeof nativeImage.createFromDataUrl, 'function')
|
||||
})
|
||||
|
||||
it('renames a property', () => {
|
||||
let msg
|
||||
deprecations.setHandler((m) => { msg = m })
|
||||
|
||||
const oldPropertyName = 'dingyOldName'
|
||||
const newPropertyName = 'shinyNewName'
|
||||
|
||||
let value = 0
|
||||
let o = { [newPropertyName]: value }
|
||||
assert.strictEqual(typeof o[oldPropertyName], 'undefined')
|
||||
assert.strictEqual(typeof o[newPropertyName], 'number')
|
||||
|
||||
deprecate.property(o, oldPropertyName, newPropertyName)
|
||||
assert.notEqual(typeof msg, 'string')
|
||||
o[oldPropertyName] = ++value
|
||||
|
||||
assert.strictEqual(typeof msg, 'string')
|
||||
assert.ok(msg.includes(oldPropertyName))
|
||||
assert.ok(msg.includes(newPropertyName))
|
||||
|
||||
assert.strictEqual(o[newPropertyName], value)
|
||||
assert.strictEqual(o[oldPropertyName], value)
|
||||
})
|
||||
|
||||
it('throws an exception if no deprecation handler is specified', () => {
|
||||
assert.throws(() => {
|
||||
deprecate.log('this is deprecated')
|
||||
|
|
Loading…
Reference in a new issue