test: 💍 add tests for format method update

This commit is contained in:
Christian Kaisermann 2019-11-29 18:39:20 -03:00
parent b8c8ba8b22
commit 0c8cc1292f

View File

@ -5,6 +5,7 @@ import {
getLocaleDictionary,
$dictionary,
} from '../../src/client/stores/dictionary'
import { $format } from '../../src/client/stores/format'
test('defineMessages returns the identity of its first argument', () => {
const obj = {}
@ -47,3 +48,26 @@ describe('waiting for a locale to load', () => {
expect(getLocaleDictionary('pt')).toMatchObject({ foo: 'foo' })
})
})
describe('changing locale', () => {
beforeEach(() => {
init({ fallbackLocale: 'en' })
})
test('format store is updated when locale changes', () => {
const fn = jest.fn()
const cancel = $format.subscribe(fn)
$locale.set('pt')
expect(fn).toHaveBeenCalledTimes(2)
cancel()
})
test('format store is updated when dictionary changes', () => {
const fn = jest.fn()
const cancel = $format.subscribe(fn)
$dictionary.set({})
expect(fn).toHaveBeenCalledTimes(2)
cancel()
})
})