From f35d22f648809e443ef605aee8db7a926b61239f Mon Sep 17 00:00:00 2001 From: "ben.12" Date: Sun, 6 Aug 2023 18:42:10 +0200 Subject: [PATCH] fix(#621) fix after rebase --- .../src/lib/transloco-validator.spec.ts | 2 +- libs/transloco/src/lib/tests/transpiler.spec.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libs/transloco-validator/src/lib/transloco-validator.spec.ts b/libs/transloco-validator/src/lib/transloco-validator.spec.ts index 8289e9eb6..4807483a6 100644 --- a/libs/transloco-validator/src/lib/transloco-validator.spec.ts +++ b/libs/transloco-validator/src/lib/transloco-validator.spec.ts @@ -23,7 +23,7 @@ describe('transloco-validator', () => { jest.mocked(fs.readFileSync).mockImplementation(() => '{"test":{"erreur"}}'); const callValidator = () => validator('', ['mytest.json']); - expect(callValidator).toThrowError(new SyntaxError("Unexpected token } in JSON at position 17 (mytest.json)")); + expect(callValidator).toThrowError(new SyntaxError("Expected ':' after property name in JSON at position 17 (mytest.json)")); }) it('should return success', () => { diff --git a/libs/transloco/src/lib/tests/transpiler.spec.ts b/libs/transloco/src/lib/tests/transpiler.spec.ts index 32795231e..97137621a 100644 --- a/libs/transloco/src/lib/tests/transpiler.spec.ts +++ b/libs/transloco/src/lib/tests/transpiler.spec.ts @@ -123,12 +123,26 @@ describe('TranslocoTranspiler', () => { function testDefaultBehaviour( parser: TranslocoTranspiler, - [start, end]: [string, string] = defaultConfig.interpolation + [start, end, forbiddenChars]: [string, string, string?] = defaultConfig.interpolation ) { function wrapParam(param: string) { return `${start} ${param} ${end}`; } + it('should skip if forbidden chars are used', () => { + if (forbiddenChars?.length) { + for (const char of forbiddenChars) { + const parsed = parser.transpile( + `Hello ${wrapParam('value ' + char)}`, + { value: 'World' }, + {}, + 'key' + ); + expect(parsed).toEqual(`Hello ${wrapParam('value ' + char)}`); + } + } + }); + it('should translate simple string from params', () => { const parsed = parser.transpile( `Hello ${wrapParam('value')}`,