spec: convert deprecations to expect (#13268)
* spec: convert deprecations to expect * address feedback from review
This commit is contained in:
parent
9a79889692
commit
cba3a9fcce
1 changed files with 26 additions and 23 deletions
|
@ -1,6 +1,10 @@
|
||||||
const assert = require('assert')
|
const chai = require('chai')
|
||||||
|
const dirtyChai = require('dirty-chai')
|
||||||
const {deprecations, deprecate, nativeImage} = require('electron')
|
const {deprecations, deprecate, nativeImage} = require('electron')
|
||||||
|
|
||||||
|
const {expect} = chai
|
||||||
|
chai.use(dirtyChai)
|
||||||
|
|
||||||
describe('deprecations', () => {
|
describe('deprecations', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
deprecations.setHandler(null)
|
deprecations.setHandler(null)
|
||||||
|
@ -10,43 +14,43 @@ describe('deprecations', () => {
|
||||||
it('allows a deprecation handler function to be specified', () => {
|
it('allows a deprecation handler function to be specified', () => {
|
||||||
const messages = []
|
const messages = []
|
||||||
|
|
||||||
deprecations.setHandler((message) => {
|
deprecations.setHandler(message => {
|
||||||
messages.push(message)
|
messages.push(message)
|
||||||
})
|
})
|
||||||
|
|
||||||
deprecate.log('this is deprecated')
|
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', () => {
|
it('returns a deprecation handler after one is set', () => {
|
||||||
const messages = []
|
const messages = []
|
||||||
|
|
||||||
deprecations.setHandler((message) => {
|
deprecations.setHandler(message => {
|
||||||
messages.push(message)
|
messages.push(message)
|
||||||
})
|
})
|
||||||
|
|
||||||
deprecate.log('this is deprecated')
|
deprecate.log('this is deprecated')
|
||||||
assert(typeof deprecations.getHandler() === 'function')
|
expect(deprecations.getHandler()).to.be.a('function')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns a deprecation warning', () => {
|
it('returns a deprecation warning', () => {
|
||||||
const messages = []
|
const messages = []
|
||||||
|
|
||||||
deprecations.setHandler((message) => {
|
deprecations.setHandler(message => {
|
||||||
messages.push(message)
|
messages.push(message)
|
||||||
})
|
})
|
||||||
|
|
||||||
deprecate.warn('old', 'new')
|
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', () => {
|
it('renames a method', () => {
|
||||||
assert.equal(typeof nativeImage.createFromDataUrl, 'undefined')
|
expect(nativeImage.createFromDataUrl).to.be.undefined()
|
||||||
assert.equal(typeof nativeImage.createFromDataURL, 'function')
|
expect(nativeImage.createFromDataURL).to.be.a('function')
|
||||||
|
|
||||||
deprecate.alias(nativeImage, 'createFromDataUrl', 'createFromDataURL')
|
deprecate.alias(nativeImage, 'createFromDataUrl', 'createFromDataURL')
|
||||||
|
|
||||||
assert.equal(typeof nativeImage.createFromDataUrl, 'function')
|
expect(nativeImage.createFromDataUrl).to.be.a('function')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renames a property', () => {
|
it('renames a property', () => {
|
||||||
|
@ -58,19 +62,18 @@ describe('deprecations', () => {
|
||||||
|
|
||||||
let value = 0
|
let value = 0
|
||||||
let o = { [newPropertyName]: value }
|
let o = { [newPropertyName]: value }
|
||||||
assert.strictEqual(typeof o[oldPropertyName], 'undefined')
|
expect(o).to.not.have.a.property(oldPropertyName)
|
||||||
assert.strictEqual(typeof o[newPropertyName], 'number')
|
expect(o).to.have.a.property(newPropertyName).that.is.a('number')
|
||||||
|
|
||||||
deprecate.property(o, oldPropertyName, newPropertyName)
|
deprecate.property(o, oldPropertyName, newPropertyName)
|
||||||
assert.notEqual(typeof msg, 'string')
|
|
||||||
o[oldPropertyName] = ++value
|
o[oldPropertyName] = ++value
|
||||||
|
|
||||||
assert.strictEqual(typeof msg, 'string')
|
expect(msg).to.be.a('string')
|
||||||
assert.ok(msg.includes(oldPropertyName))
|
expect(msg).to.include(oldPropertyName)
|
||||||
assert.ok(msg.includes(newPropertyName))
|
expect(msg).to.include(newPropertyName)
|
||||||
|
|
||||||
assert.strictEqual(o[newPropertyName], value)
|
expect(o).to.have.a.property(newPropertyName).that.is.equal(value)
|
||||||
assert.strictEqual(o[oldPropertyName], value)
|
expect(o).to.have.a.property(oldPropertyName).that.is.equal(value)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('warns if deprecated property is already set', () => {
|
it('warns if deprecated property is already set', () => {
|
||||||
|
@ -84,14 +87,14 @@ describe('deprecations', () => {
|
||||||
let o = { [oldPropertyName]: value }
|
let o = { [oldPropertyName]: value }
|
||||||
deprecate.property(o, oldPropertyName, newPropertyName)
|
deprecate.property(o, oldPropertyName, newPropertyName)
|
||||||
|
|
||||||
assert.strictEqual(typeof msg, 'string')
|
expect(msg).to.be.a('string')
|
||||||
assert.ok(msg.includes(oldPropertyName))
|
expect(msg).to.include(oldPropertyName)
|
||||||
assert.ok(msg.includes(newPropertyName))
|
expect(msg).to.include(newPropertyName)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws an exception if no deprecation handler is specified', () => {
|
it('throws an exception if no deprecation handler is specified', () => {
|
||||||
assert.throws(() => {
|
expect(() => {
|
||||||
deprecate.log('this is deprecated')
|
deprecate.log('this is deprecated')
|
||||||
}, /this is deprecated/)
|
}).to.throw(/this is deprecated/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue