-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad073f9
commit 0e8b26e
Showing
1 changed file
with
48 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
/* eslint-env jest */ | ||
|
||
import I18n from './i18n.mjs' | ||
|
||
describe('I18n', () => { | ||
|
||
describe('retrieving translations', () => { | ||
let config = {} | ||
|
||
beforeEach(() => { | ||
config = { | ||
textString: 'Hello world', | ||
htmlString: 'Hello<span class="govuk-visually-hidden"> world</span>' | ||
} | ||
}) | ||
|
||
test('returns the text for a given lookup key', () => { | ||
const i18n = new I18n(config) | ||
|
||
let returnString = i18n.t('textString') | ||
expect(returnString).toBe('Hello world') | ||
}) | ||
|
||
test('returns the HTML for a given lookup key', () => { | ||
const i18n = new I18n(config) | ||
|
||
let returnString = i18n.t('htmlString') | ||
expect(returnString).toBe('Hello<span class="govuk-visually-hidden"> world</span>') | ||
}) | ||
|
||
test('returns the lookup key if no translation is defined', () => { | ||
const i18n = new I18n(config) | ||
|
||
let returnString = i18n.t('missingString') | ||
expect(returnString).toBe('missingString') | ||
}) | ||
|
||
test('throws an error if no lookup key is provided', () => { | ||
const i18n = new I18n(config) | ||
|
||
expect(() => i18n.t()).toThrow('i18n lookup key missing.') | ||
}) | ||
|
||
}) | ||
}) |