From 3206df25eee0a60c30d381da0d3dc08ce6929623 Mon Sep 17 00:00:00 2001 From: Hiroshi Nishijima Date: Tue, 15 Jun 2021 23:13:28 +0900 Subject: [PATCH 1/3] Relaxed the validation to allow multibyte strings --- packages/jest-each/src/validation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-each/src/validation.ts b/packages/jest-each/src/validation.ts index 3355023150ff..52238ed53283 100644 --- a/packages/jest-each/src/validation.ts +++ b/packages/jest-each/src/validation.ts @@ -77,7 +77,7 @@ const pluralize = (word: string, count: number) => const START_OF_LINE = '^'; const NEWLINE = '\\n'; -const HEADING = '\\s*\\w+\\s*'; +const HEADING = '\\s*[^\\s]+\\s*'; const PIPE = '\\|'; const REPEATABLE_HEADING = `(${PIPE}${HEADING})*`; const HEADINGS_FORMAT = new RegExp( From ba46bd3f0aa1b51bf21bc48d9b3d39b2962db874 Mon Sep 17 00:00:00 2001 From: Hiroshi Nishijima Date: Sun, 22 Aug 2021 11:59:49 +0900 Subject: [PATCH 2/3] Added test cases to check support multibyte characters --- .../jest-each/src/__tests__/template.test.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/packages/jest-each/src/__tests__/template.test.ts b/packages/jest-each/src/__tests__/template.test.ts index 5fc5d657d780..f39031840f93 100644 --- a/packages/jest-each/src/__tests__/template.test.ts +++ b/packages/jest-each/src/__tests__/template.test.ts @@ -70,6 +70,26 @@ describe('jest-each', () => { expect(testCallBack).not.toHaveBeenCalled(); }); + test('does not throw error when there are multibyte characters in first column headings', () => { + const globalTestMocks = getGlobalTestMocks(); + const eachObject = each.withGlobal(globalTestMocks)` + ʅ(ツ)ʃ | b | expected + ${1} | ${1} | ${2} + `; + const testFunction = get(eachObject, keyPath); + const testCallBack = jest.fn(); + testFunction('accept multibyte characters', testCallBack); + + const globalMock = get(globalTestMocks, keyPath); + + expect(() => globalMock.mock.calls[0][1]()).not.toThrowError(); + expect(testCallBack).toHaveBeenCalledWith({ + b: 1, + expected: 2, + 'ʅ(ツ)ʃ': 1, + }); + }); + test('throws error when there are additional words in second column heading', () => { const globalTestMocks = getGlobalTestMocks(); const eachObject = each.withGlobal(globalTestMocks)` @@ -88,6 +108,26 @@ describe('jest-each', () => { expect(testCallBack).not.toHaveBeenCalled(); }); + test('does not throw error when there are multibyte characters in second column headings', () => { + const globalTestMocks = getGlobalTestMocks(); + const eachObject = each.withGlobal(globalTestMocks)` + a | ☝(ʕ⊙ḕ⊙ʔ)☝ | expected + ${1} | ${1} | ${2} + `; + const testFunction = get(eachObject, keyPath); + const testCallBack = jest.fn(); + testFunction('accept multibyte characters', testCallBack); + + const globalMock = get(globalTestMocks, keyPath); + + expect(() => globalMock.mock.calls[0][1]()).not.toThrowError(); + expect(testCallBack).toHaveBeenCalledWith({ + a: 1, + expected: 2, + '☝(ʕ⊙ḕ⊙ʔ)☝': 1, + }); + }); + test('throws error when there are additional words in last column heading', () => { const globalTestMocks = getGlobalTestMocks(); const eachObject = each.withGlobal(globalTestMocks)` @@ -106,6 +146,26 @@ describe('jest-each', () => { expect(testCallBack).not.toHaveBeenCalled(); }); + test('does not throw error when there are multibyte characters in last column headings', () => { + const globalTestMocks = getGlobalTestMocks(); + const eachObject = each.withGlobal(globalTestMocks)` + a | b | (๑ఠ‿ఠ๑)<expected + ${1} | ${1} | ${2} + `; + const testFunction = get(eachObject, keyPath); + const testCallBack = jest.fn(); + testFunction('accept multibyte characters', testCallBack); + + const globalMock = get(globalTestMocks, keyPath); + + expect(() => globalMock.mock.calls[0][1]()).not.toThrowError(); + expect(testCallBack).toHaveBeenCalledWith({ + '(๑ఠ‿ఠ๑)<expected': 2, + a: 1, + b: 1, + }); + }); + test('does not throw error when there is additional words in template after heading row', () => { const globalTestMocks = getGlobalTestMocks(); const eachObject = each.withGlobal(globalTestMocks)` From 061c053c64d6f36c2515cdd33e9b3e64641751dd Mon Sep 17 00:00:00 2001 From: Hiroshi Nishijima Date: Sun, 22 Aug 2021 12:33:10 +0900 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60e15e30b962..79f19e456434 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `[jest-environment-node]` Add `Event` and `EventTarget` to node global environment. ([#11705](https://github.com/facebook/jest/issues/11705)) - `[jest-mock]` Fix `spyOn` to use `Object.prototype.hasOwnProperty` [#11721](https://github.com/facebook/jest/pull/11721) - `[jest-resolver]` Add dependency on `jest-haste-map` [#11759](https://github.com/facebook/jest/pull/11759) +- `[jest-each]` Relaxed the validation to allow multibyte characters in headings ([#11575](https://github.com/facebook/jest/pull/11575)) ### Chore & Maintenance