From e3f62dc619764ffa18a394815c193fdcefce947d Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 18 Sep 2023 20:34:56 +0200 Subject: [PATCH] avoid as const in TranslationApi tests Signed-off-by: Patrik Oldsberg --- .../TranslationApi/I18nextTranslationApi.test.ts | 14 +++++++------- .../TranslationApi/MockTranslationApi.test.ts | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.test.ts b/packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.test.ts index b53a285342..224430752c 100644 --- a/packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.test.ts +++ b/packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.test.ts @@ -383,7 +383,7 @@ describe('I18nextTranslationApi', () => { describe('formatting', () => { function snapshotWithMessages< - TMessages extends { [key in string]: string }, + const TMessages extends { [key in string]: string }, >(messages: TMessages) { const translationApi = I18nextTranslationApi.create({ languageApi: AppLanguageSelector.create(), @@ -400,7 +400,7 @@ describe('I18nextTranslationApi', () => { foo: 'Foo', bar: 'Bar', baz: 'Baz', - } as const); + }); expect(snapshot.t('foo')).toBe('Foo'); expect(snapshot.t('bar')).toBe('Bar'); @@ -412,7 +412,7 @@ describe('I18nextTranslationApi', () => { shallow: 'Foo {{ bar }}', multiple: 'Foo {{ bar }} {{ baz }}', deep: 'Foo {{ bar.baz }}', - } as const); + }); // @ts-expect-error expect(snapshot.t('shallow')).toBe('Foo {{ bar }}'); @@ -441,7 +441,7 @@ describe('I18nextTranslationApi', () => { it('should not escape by default', () => { const snapshot = snapshotWithMessages({ foo: 'Foo {{ foo }}', - } as const); + }); expect(snapshot.t('foo', { replace: { foo: '
' } })).toBe( 'Foo
', @@ -459,7 +459,7 @@ describe('I18nextTranslationApi', () => { foo: 'Foo $t(bar) $t(baz)', bar: 'Nested', baz: 'Baz {{ qux }}', - } as const); + }); expect(snapshot.t('foo', { qux: 'Deep' })).toBe('Foo Nested Baz Deep'); }); @@ -474,7 +474,7 @@ describe('I18nextTranslationApi', () => { relativeSecondsShort: '= {{ x, relativeTime(range: second; style: short) }}', list: '= {{ x, list }}', - } as const); + }); expect(snapshot.t('plain', { replace: { x: '5' } })).toBe('= 5'); expect(snapshot.t('number', { replace: { x: 5 } })).toBe('= 5'); @@ -530,7 +530,7 @@ describe('I18nextTranslationApi', () => { derp_other: 'derps', derpWithCount_one: '{{ count }} derp', derpWithCount_other: '{{ count }} derps', - } as const); + }); expect(snapshot.t('derp', { count: 1 })).toBe('derp'); expect(snapshot.t('derp', { count: 2 })).toBe('derps'); diff --git a/packages/test-utils/src/testUtils/apis/TranslationApi/MockTranslationApi.test.ts b/packages/test-utils/src/testUtils/apis/TranslationApi/MockTranslationApi.test.ts index 45d23d9db2..0cc755ecb5 100644 --- a/packages/test-utils/src/testUtils/apis/TranslationApi/MockTranslationApi.test.ts +++ b/packages/test-utils/src/testUtils/apis/TranslationApi/MockTranslationApi.test.ts @@ -18,9 +18,9 @@ import { createTranslationRef } from '@backstage/core-plugin-api/alpha'; import { MockTranslationApi } from './MockTranslationApi'; describe('MockTranslationApi', () => { - function snapshotWithMessages( - messages: TMessages, - ) { + function snapshotWithMessages< + const TMessages extends { [key in string]: string }, + >(messages: TMessages) { const translationApi = MockTranslationApi.create(); const ref = createTranslationRef({ id: 'test', @@ -50,7 +50,7 @@ describe('MockTranslationApi', () => { shallow: 'Foo {{ bar }}', multiple: 'Foo {{ bar }} {{ baz }}', deep: 'Foo {{ bar.baz }}', - } as const); + }); // @ts-expect-error expect(snapshot.t('shallow')).toBe('Foo {{ bar }}'); @@ -73,7 +73,7 @@ describe('MockTranslationApi', () => { it('should not escape by default', () => { const snapshot = snapshotWithMessages({ foo: 'Foo {{ foo }}', - } as const); + }); expect(snapshot.t('foo', { foo: '
' })).toBe('Foo
'); expect( @@ -89,7 +89,7 @@ describe('MockTranslationApi', () => { foo: 'Foo $t(bar) $t(baz)', bar: 'Nested', baz: 'Baz {{ qux }}', - } as const); + }); expect(snapshot.t('foo', { qux: 'Deep' })).toBe('Foo Nested Baz Deep'); }); @@ -104,7 +104,7 @@ describe('MockTranslationApi', () => { relativeSecondsShort: '= {{ x, relativeTime(range: second; style: short) }}', list: '= {{ x, list }}', - } as const); + }); expect(snapshot.t('plain', { x: '5' })).toBe('= 5'); expect(snapshot.t('number', { x: 5 })).toBe('= 5'); @@ -154,7 +154,7 @@ describe('MockTranslationApi', () => { derp_other: 'derps', derpWithCount_one: '{{ count }} derp', derpWithCount_other: '{{ count }} derps', - } as const); + }); expect(snapshot.t('derp', { count: 1 })).toBe('derp'); expect(snapshot.t('derp', { count: 2 })).toBe('derps');