/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/controller/test/shared.js
47 строк
2 KB
arthur791004
I18N: Fix the lib/wp was called before locale data was ready (#107124)
17 ноя 2025, 04:47
Не верифицирован
17 ноя 2025, 04:47
fe7856e
Код
Авторство
О чём код?
import { setLocale } from '../../state/ui/language/actions'; import { setLocaleMiddleware } from '../shared'; jest.mock( '../../state/ui/language/actions', () => ( { setLocale: jest.fn( () => jest.fn() ), } ) ); describe( 'setLocaleMiddleware', () => { const next = jest.fn(); const dispatch = jest.fn(); let context; let middleware; beforeEach( () => { next.mockClear(); dispatch.mockClear(); setLocale.mockClear(); context = { query: {}, params: {}, store: { dispatch } }; middleware = setLocaleMiddleware(); } ); it( "doesn't dispatch locale event if no language params found", () => { middleware( context, next ); expect( next ).toHaveBeenCalledTimes( 1 ); expect( context.store.dispatch ).toHaveBeenCalledTimes( 0 ); } ); it( 'Dispatch locale event if language param is in URL', () => { context.params.lang = 'fr'; middleware( context, next ); expect( next ).toHaveBeenCalledTimes( 1 ); expect( context.store.dispatch ).toHaveBeenCalledTimes( 1 ); expect( setLocale ).toHaveBeenCalledWith( 'fr' ); // expect( context.store.dispatch ).toHaveBeenCalledWith( setLocale( 'fr' ) ); expect( context.lang ).toEqual( 'fr' ); } ); it( 'Dispatch locale event if language param is query param', () => { context.query.lang = 'fr'; middleware( context, next ); expect( next ).toHaveBeenCalledTimes( 1 ); expect( context.store.dispatch ).toHaveBeenCalledTimes( 1 ); expect( setLocale ).toHaveBeenCalledWith( 'fr' ); // expect( context.store.dispatch ).toHaveBeenCalledWith( setLocale( 'fr' ) ); expect( context.lang ).toEqual( 'fr' ); } ); } );