This repository has been archived by the owner on May 19, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(directive): deprecate 'language' prop for directive
- Loading branch information
1 parent
d8f5fba
commit 5a4d082
Showing
4 changed files
with
81 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
/* eslint-disable import/prefer-default-export */ | ||
|
||
export function log(message) { | ||
if (typeof console !== 'undefined') { | ||
console.warn(message); // eslint-disable-line no-console | ||
} | ||
} | ||
|
||
export function warn(message) { | ||
log(`[vue-i18next warn]: ${message}`); | ||
} | ||
|
||
export function deprecate(message) { | ||
log(`[vue-i18next deprecated]: ${message}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
import { deprecate, log, warn } from '../../src/utils'; | ||
|
||
describe('utils', () => { | ||
describe('log', () => { | ||
it('call console.warn if console is present', () => { | ||
const spy = sinon.spy(console, 'warn'); | ||
|
||
log('test warning'); | ||
expect(spy.notCalled).to.equal(false); | ||
expect(spy.callCount).to.equal(1); | ||
spy.restore(); | ||
}); | ||
|
||
it('does nothing if console is not present', () => { | ||
const spy = sinon.spy(console, 'warn'); | ||
const _console = window.console; | ||
|
||
window.console = undefined; | ||
log('test warning'); | ||
window.console = _console; | ||
|
||
expect(spy.notCalled).to.equal(true); | ||
spy.restore(); | ||
}); | ||
}); | ||
|
||
describe('warn', () => { | ||
it('print error to console if called', () => { | ||
const spy = sinon.spy(console, 'warn'); | ||
|
||
warn('warned'); | ||
expect(spy.notCalled).to.equal(false); | ||
expect(spy.getCall(0).calledWith('[vue-i18next warn]: warned')).to.equal(true); | ||
spy.restore(); | ||
}); | ||
}); | ||
|
||
describe('deprecate', () => { | ||
it('print deprecation message to console if called', () => { | ||
const spy = sinon.spy(console, 'warn'); | ||
|
||
deprecate('use something other'); | ||
expect(spy.notCalled).to.equal(false); | ||
expect(spy.getCall(0).calledWith('[vue-i18next deprecated]: use something other')).to.equal(true); | ||
spy.restore(); | ||
}); | ||
}); | ||
}); |