diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c6f60a95601..80a65e3e5d4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes +- `[jest-each]` Relaxed the validation to allow multibyte characters in headings ([#11575](https://github.com/facebook/jest/pull/11575)) - `[jest-environment-jsdom]` Add support for `userAgent` option ([#11773](https://github.com/facebook/jest/pull/11773)) - `[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) 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)` 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(