Skip to content
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

tests(i18n): no ICU value given to preprocess #9384

Merged
merged 4 commits into from
Jul 17, 2019
Merged
Prev Previous commit
Next Next commit
updated with another test. added var to error out.
  • Loading branch information
exterkamp committed Jul 17, 2019
commit db5a70a0b79f0837eeec18313959e9107547370e
2 changes: 1 addition & 1 deletion lighthouse-core/lib/i18n/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function _preprocessMessageValues(icuMessage, values = {}) {
.filter(el => el.type === 'argumentElement')
.forEach(el => {
if (el.id && (el.id in values) === false) {
throw new Error('ICU Message contains a value reference that wasn\'t provided');
throw new Error(`ICU Message contains a value reference ("${el.id}") that wasn't provided`);
}
});

Expand Down
11 changes: 9 additions & 2 deletions lighthouse-core/test/lib/i18n/i18n-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('i18n', () => {
helloSecWorld: 'Hello {in, number, seconds} World',
helloTimeInMsWorld: 'Hello {timeInMs, number, seconds} World',
helloPercentWorld: 'Hello {in, number, extendedPercent} World',
helloWorldMultiReplace: '{hello} {world}',
};
const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);

Expand Down Expand Up @@ -136,8 +137,14 @@ describe('i18n', () => {
});

it('throws an error when a value is not provided', () => {
exterkamp marked this conversation as resolved.
Show resolved Hide resolved
expect(_ => i18n.getFormatted(str_(UIStrings.helloBytesWorld, {}), 'en-US'))
.toThrow(`ICU Message contains a value reference that wasn't provided`);
expect(_ => i18n.getFormatted(str_(UIStrings.helloBytesWorld), 'en-US'))
.toThrow(`ICU Message contains a value reference ("in") that wasn't provided`);
});

it('throws an error when a value is missing', () => {
expect(_ => i18n.getFormatted(str_(UIStrings.helloWorldMultiReplace,
{hello: 'hello'}), 'en-US'))
.toThrow(`ICU Message contains a value reference ("world") that wasn't provided`);
});
});
});