chore: refactor deprecation apis (#14495)
This commit is contained in:
parent
3a6e88c0e7
commit
2157d09956
3 changed files with 148 additions and 146 deletions
|
@ -5,7 +5,7 @@ const {deprecations, deprecate, nativeImage} = require('electron')
|
|||
const {expect} = chai
|
||||
chai.use(dirtyChai)
|
||||
|
||||
describe('deprecations', () => {
|
||||
describe.only('deprecations', () => {
|
||||
beforeEach(() => {
|
||||
deprecations.setHandler(null)
|
||||
process.throwDeprecation = true
|
||||
|
@ -55,54 +55,64 @@ describe('deprecations', () => {
|
|||
|
||||
it('renames a property', () => {
|
||||
let msg
|
||||
deprecations.setHandler((m) => { msg = m })
|
||||
deprecations.setHandler(m => { msg = m })
|
||||
|
||||
const oldPropertyName = 'dingyOldName'
|
||||
const newPropertyName = 'shinyNewName'
|
||||
const oldProp = 'dingyOldName'
|
||||
const newProp = 'shinyNewName'
|
||||
|
||||
let value = 0
|
||||
let o = { [newPropertyName]: value }
|
||||
expect(o).to.not.have.a.property(oldPropertyName)
|
||||
expect(o).to.have.a.property(newPropertyName).that.is.a('number')
|
||||
const o = {[newProp]: value}
|
||||
expect(o).to.not.have.a.property(oldProp)
|
||||
expect(o).to.have.a.property(newProp).that.is.a('number')
|
||||
|
||||
deprecate.renameProperty(o, oldPropertyName, newPropertyName)
|
||||
o[oldPropertyName] = ++value
|
||||
deprecate.renameProperty(o, oldProp, newProp)
|
||||
o[oldProp] = ++value
|
||||
|
||||
expect(msg).to.be.a('string')
|
||||
expect(msg).to.include(oldPropertyName)
|
||||
expect(msg).to.include(newPropertyName)
|
||||
expect(msg).to.include(oldProp)
|
||||
expect(msg).to.include(newProp)
|
||||
|
||||
expect(o).to.have.a.property(newPropertyName).that.is.equal(value)
|
||||
expect(o).to.have.a.property(oldPropertyName).that.is.equal(value)
|
||||
expect(o).to.have.a.property(newProp).that.is.equal(value)
|
||||
expect(o).to.have.a.property(oldProp).that.is.equal(value)
|
||||
})
|
||||
|
||||
it('doesn\'t deprecate a property not on an object', () => {
|
||||
const o = {}
|
||||
|
||||
expect(() => {
|
||||
deprecate.removeProperty(o, 'iDontExist')
|
||||
}).to.throw(/Cannot deprecate a property on an object which does not have that property/)
|
||||
})
|
||||
|
||||
it('deprecates a property of an object', () => {
|
||||
let msg
|
||||
deprecations.setHandler(m => { msg = m })
|
||||
|
||||
const propertyName = 'itMustGo'
|
||||
const o = { [propertyName]: 0 }
|
||||
const prop = 'itMustGo'
|
||||
let o = {[prop]: 0}
|
||||
|
||||
deprecate.removeProperty(o, propertyName)
|
||||
deprecate.removeProperty(o, prop)
|
||||
|
||||
const temp = o[prop]
|
||||
|
||||
expect(temp).to.equal(0)
|
||||
expect(msg).to.be.a('string')
|
||||
expect(msg).to.include(propertyName)
|
||||
expect(msg).to.include(prop)
|
||||
})
|
||||
|
||||
it('warns if deprecated property is already set', () => {
|
||||
let msg
|
||||
deprecations.setHandler((m) => { msg = m })
|
||||
deprecations.setHandler(m => { msg = m })
|
||||
|
||||
const oldPropertyName = 'dingyOldName'
|
||||
const newPropertyName = 'shinyNewName'
|
||||
const value = 0
|
||||
const oldProp = 'dingyOldName'
|
||||
const newProp = 'shinyNewName'
|
||||
|
||||
let o = { [oldPropertyName]: value }
|
||||
deprecate.renameProperty(o, oldPropertyName, newPropertyName)
|
||||
let o = {[oldProp]: 0}
|
||||
deprecate.renameProperty(o, oldProp, newProp)
|
||||
|
||||
expect(msg).to.be.a('string')
|
||||
expect(msg).to.include(oldPropertyName)
|
||||
expect(msg).to.include(newPropertyName)
|
||||
expect(msg).to.include(oldProp)
|
||||
expect(msg).to.include(newProp)
|
||||
})
|
||||
|
||||
it('throws an exception if no deprecation handler is specified', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue