From cba3a9fcce601d5899061ac6a578d4b4fc33e8fc Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 19 Jun 2018 08:22:08 -0700 Subject: [PATCH] spec: convert deprecations to expect (#13268) * spec: convert deprecations to expect * address feedback from review --- spec/api-deprecations-spec.js | 49 +++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/spec/api-deprecations-spec.js b/spec/api-deprecations-spec.js index d5e99a3336df..8bb0711b72b5 100644 --- a/spec/api-deprecations-spec.js +++ b/spec/api-deprecations-spec.js @@ -1,6 +1,10 @@ -const assert = require('assert') +const chai = require('chai') +const dirtyChai = require('dirty-chai') const {deprecations, deprecate, nativeImage} = require('electron') +const {expect} = chai +chai.use(dirtyChai) + describe('deprecations', () => { beforeEach(() => { deprecations.setHandler(null) @@ -10,43 +14,43 @@ describe('deprecations', () => { it('allows a deprecation handler function to be specified', () => { const messages = [] - deprecations.setHandler((message) => { + deprecations.setHandler(message => { messages.push(message) }) deprecate.log('this is deprecated') - assert.deepEqual(messages, ['this is deprecated']) + expect(messages).to.deep.equal(['this is deprecated']) }) it('returns a deprecation handler after one is set', () => { const messages = [] - deprecations.setHandler((message) => { + deprecations.setHandler(message => { messages.push(message) }) deprecate.log('this is deprecated') - assert(typeof deprecations.getHandler() === 'function') + expect(deprecations.getHandler()).to.be.a('function') }) it('returns a deprecation warning', () => { const messages = [] - deprecations.setHandler((message) => { + deprecations.setHandler(message => { messages.push(message) }) deprecate.warn('old', 'new') - assert.deepEqual(messages, [`'old' is deprecated. Use 'new' instead.`]) + expect(messages).to.deep.equal([`'old' is deprecated. Use 'new' instead.`]) }) it('renames a method', () => { - assert.equal(typeof nativeImage.createFromDataUrl, 'undefined') - assert.equal(typeof nativeImage.createFromDataURL, 'function') + expect(nativeImage.createFromDataUrl).to.be.undefined() + expect(nativeImage.createFromDataURL).to.be.a('function') deprecate.alias(nativeImage, 'createFromDataUrl', 'createFromDataURL') - assert.equal(typeof nativeImage.createFromDataUrl, 'function') + expect(nativeImage.createFromDataUrl).to.be.a('function') }) it('renames a property', () => { @@ -58,19 +62,18 @@ describe('deprecations', () => { let value = 0 let o = { [newPropertyName]: value } - assert.strictEqual(typeof o[oldPropertyName], 'undefined') - assert.strictEqual(typeof o[newPropertyName], 'number') + expect(o).to.not.have.a.property(oldPropertyName) + expect(o).to.have.a.property(newPropertyName).that.is.a('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)) + expect(msg).to.be.a('string') + expect(msg).to.include(oldPropertyName) + expect(msg).to.include(newPropertyName) - assert.strictEqual(o[newPropertyName], value) - assert.strictEqual(o[oldPropertyName], value) + expect(o).to.have.a.property(newPropertyName).that.is.equal(value) + expect(o).to.have.a.property(oldPropertyName).that.is.equal(value) }) it('warns if deprecated property is already set', () => { @@ -84,14 +87,14 @@ describe('deprecations', () => { let o = { [oldPropertyName]: value } deprecate.property(o, oldPropertyName, newPropertyName) - assert.strictEqual(typeof msg, 'string') - assert.ok(msg.includes(oldPropertyName)) - assert.ok(msg.includes(newPropertyName)) + expect(msg).to.be.a('string') + expect(msg).to.include(oldPropertyName) + expect(msg).to.include(newPropertyName) }) it('throws an exception if no deprecation handler is specified', () => { - assert.throws(() => { + expect(() => { deprecate.log('this is deprecated') - }, /this is deprecated/) + }).to.throw(/this is deprecated/) }) })