From 61fac1bbc13d624f2f53e839317f22bb15a0729c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 29 May 2018 15:40:48 +0200 Subject: [PATCH] test: add tests for deprecate.property() --- spec/api-deprecations-spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/api-deprecations-spec.js b/spec/api-deprecations-spec.js index 9f30efed3dca..0c872b83435c 100644 --- a/spec/api-deprecations-spec.js +++ b/spec/api-deprecations-spec.js @@ -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')