New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add to deprecations spec #11117
Add to deprecations spec #11117
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const assert = require('assert') | ||
const {deprecations, deprecate} = require('electron') | ||
const {deprecations, deprecate, nativeImage} = require('electron') | ||
|
||
describe('deprecations', () => { | ||
beforeEach(() => { | ||
|
@@ -18,6 +18,37 @@ describe('deprecations', () => { | |
assert.deepEqual(messages, ['this is deprecated']) | ||
}) | ||
|
||
it('returns a deprecation handler after one is set', () => { | ||
const messages = [] | ||
|
||
deprecations.setHandler((message) => { | ||
messages.push(message) | ||
}) | ||
|
||
deprecate.log('this is deprecated') | ||
assert(typeof deprecations.getHandler() === 'function') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
|
||
it('returns a deprecation warning', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it('invokes the handler when set') |
||
const messages = [] | ||
|
||
deprecations.setHandler((message) => { | ||
messages.push(message) | ||
}) | ||
|
||
deprecate.warn('old', 'new') | ||
assert.deepEqual(messages, [`'old' is deprecated. Use 'new' instead.`]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is OK but a little brittle, it'll fail if we ever change the warning format. What would you think about something like
|
||
}) | ||
|
||
it('renames a method', () => { | ||
assert.equal(typeof nativeImage.createFromDataUrl, 'undefined') | ||
assert.equal(typeof nativeImage.createFromDataURL, 'function') | ||
|
||
deprecate.alias(nativeImage, 'createFromDataUrl', 'createFromDataURL') | ||
|
||
assert.equal(typeof nativeImage.createFromDataUrl, 'function') | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good start but, thinking it over a little, I think this is not a good test of the alias feature. We'd be better off confirming that warnings happen and that
|
||
|
||
it('throws an exception if no deprecation handler is specified', () => { | ||
assert.throws(() => { | ||
deprecate.log('this is deprecated') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
messages
is unused here and thedeprecate.log()
call is unrelated to the test. Looks like these are a copy-paste leftover; all that's really needed for this test is something likedeprecations.setHandler(message => {})