test: add tests for deprecate.property()

This commit is contained in:
Charles Kerr 2018-05-29 15:40:48 +02:00
parent 0a614217ce
commit 61fac1bbc1

View file

@ -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')