-
-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐ new: HTML locale message warning option (#567)
* ⭐ new: allow html foratting option * fix new feature API name * implement logic * fix: change to 'off' from 'allow' * fix: flow error * fix: tweak console message * refactor * fix: regex miss-take
- Loading branch information
Showing
7 changed files
with
302 additions
and
2 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
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,149 @@ | ||
describe('warnHtmlInMessage', () => { | ||
let spyWarn | ||
let spyError | ||
beforeEach(() => { | ||
spyWarn = sinon.spy(console, 'warn') | ||
spyError = sinon.spy(console, 'error') | ||
}) | ||
afterEach(() => { | ||
spyWarn.restore() | ||
spyError.restore() | ||
}) | ||
|
||
describe('constructor option', () => { | ||
it('should be worked', () => { | ||
const messages = { | ||
en: { | ||
message: { | ||
foo: { | ||
buz: '<p>buz</p>', | ||
hello: 'hello' | ||
}, | ||
bar: [1, { buz: '<p>buz</p>' }], | ||
buz: 22 | ||
} | ||
}, | ||
ja: { message: '<p>こんにちは</p>' } | ||
} | ||
|
||
// `off` | ||
new VueI18n({ | ||
warnHtmlInMessage: 'off', | ||
messages | ||
}) | ||
assert(spyWarn.callCount === 0) | ||
assert(spyError.callCount === 0) | ||
|
||
// `warn` | ||
new VueI18n({ | ||
warnHtmlInMessage: 'warn', | ||
messages | ||
}) | ||
assert(spyWarn.callCount === 3) | ||
assert(spyError.callCount === 0) | ||
|
||
// `error` | ||
new VueI18n({ | ||
warnHtmlInMessage: 'error', | ||
messages | ||
}) | ||
assert(spyWarn.callCount === 3) | ||
assert(spyError.callCount === 3) | ||
}) | ||
}) | ||
|
||
describe('property', () => { | ||
it('should be worked', () => { | ||
const messages = { | ||
en: { | ||
message: { | ||
foo: { | ||
buz: '<p>buz</p>' | ||
}, | ||
bar: [1, '<p>bar</p>'], | ||
buz: 22 | ||
} | ||
}, | ||
ja: { message: '<p>こんにちは</p>' } | ||
} | ||
|
||
const i18n = new VueI18n({ | ||
warnHtmlInMessage: 'off', | ||
messages | ||
}) | ||
|
||
// `warn` | ||
i18n.warnHtmlInMessage = 'warn' | ||
assert(spyWarn.callCount === 3) | ||
assert(spyError.callCount === 0) | ||
|
||
// `error` | ||
i18n.warnHtmlInMessage = 'error' | ||
assert(spyWarn.callCount === 3) | ||
assert(spyError.callCount === 3) | ||
|
||
// `off` | ||
i18n.warnHtmlInMessage = 'off' | ||
assert(spyWarn.callCount === 3) | ||
assert(spyError.callCount === 3) | ||
}) | ||
}) | ||
|
||
describe('setLocaleMessage', () => { | ||
it('should be worked', () => { | ||
const i18n = new VueI18n({ | ||
warnHtmlInMessage: 'warn', | ||
messages: { | ||
en: {}, | ||
ja: {} | ||
} | ||
}) | ||
|
||
i18n.setLocaleMessage('en', { | ||
hello: '<p>hello</p>' | ||
}) | ||
assert(spyWarn.callCount === 1) | ||
assert(spyError.callCount === 0) | ||
|
||
i18n.warnHtmlInMessage = 'error' | ||
i18n.setLocaleMessage('ja', { | ||
hello: '<p>こんにちは</p>' | ||
}) | ||
assert(spyWarn.callCount === 1) | ||
assert(spyError.callCount === 2) | ||
|
||
i18n.warnHtmlInMessage = 'off' | ||
assert(spyWarn.callCount === 1) | ||
assert(spyError.callCount === 2) | ||
}) | ||
}) | ||
|
||
describe('mergeLocaleMessage', () => { | ||
it('should be worked', () => { | ||
const i18n = new VueI18n({ | ||
warnHtmlInMessage: 'warn', | ||
messages: { | ||
en: {}, | ||
ja: {} | ||
} | ||
}) | ||
|
||
i18n.mergeLocaleMessage('en', { | ||
hello: '<p>hello</p>' | ||
}) | ||
assert(spyWarn.callCount === 1) | ||
assert(spyError.callCount === 0) | ||
|
||
i18n.warnHtmlInMessage = 'error' | ||
i18n.mergeLocaleMessage('ja', { | ||
hello: '<p>こんにちは</p>' | ||
}) | ||
assert(spyWarn.callCount === 1) | ||
assert(spyError.callCount === 2) | ||
|
||
i18n.warnHtmlInMessage = 'off' | ||
assert(spyWarn.callCount === 1) | ||
assert(spyError.callCount === 2) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.