Skip to content

Commit cbf4a10

Browse files
committed
More tests
1 parent 076a9ac commit cbf4a10

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

packages/i18next/src/integration.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@ export function createI18nextIntegration({
175175
variables?: Record<string, Store<string>>
176176
): Store<string> {
177177
return combine(
178-
{ t: $t, variables: combine(variables ?? {}) },
179-
({ t, variables }) => t(key, variables) ?? key
178+
{
179+
t: $t,
180+
variables: variables
181+
? combine(variables)
182+
: createStore(null, { serialize: 'ignore' }),
183+
},
184+
({ t, variables }) => t(key, variables ?? undefined) ?? key
180185
);
181186
}
182187

packages/i18next/src/translated.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,40 @@ describe('integration.translated', () => {
116116

117117
expect(scope.getState($result)).toBe('valueOne kek');
118118
});
119+
120+
test('changes after language changed', async () => {
121+
const instance = createInstance({
122+
resources: {
123+
th: { common: { key: 'valueOne {{name}}' } },
124+
en: { common: { key: 'valueTwo {{name}}' } },
125+
},
126+
lng: 'th',
127+
});
128+
129+
const setup = createEvent();
130+
131+
const { translated, changeLanguageFx } = createI18nextIntegration({
132+
instance,
133+
setup,
134+
});
135+
136+
const $name = createStore('wow');
137+
138+
const $result = translated('common:key', { name: $name });
139+
140+
const scope = fork();
141+
142+
await allSettled(setup, { scope });
143+
144+
expect(scope.getState($result)).toBe('valueOne wow');
145+
146+
await allSettled(changeLanguageFx, { scope, params: 'en' });
147+
148+
expect(scope.getState($result)).toBe('valueTwo wow');
149+
150+
await allSettled($name, { scope, params: 'kek' });
151+
152+
expect(scope.getState($result)).toBe('valueTwo kek');
153+
});
119154
});
120155
});

0 commit comments

Comments
 (0)