Skip to content

Commit 499ef4f

Browse files
authored
[jest-each] Relaxed the validation to allow multibyte characters in headings (#11575)
1 parent d455d2d commit 499ef4f

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
### Fixes
99

10+
- `[jest-each]` Relaxed the validation to allow multibyte characters in headings ([#11575](https://github.com/facebook/jest/pull/11575))
1011
- `[jest-environment-jsdom]` Add support for `userAgent` option ([#11773](https://github.com/facebook/jest/pull/11773))
1112
- `[jest-environment-node]` Add `Event` and `EventTarget` to node global environment. ([#11705](https://github.com/facebook/jest/issues/11705))
1213
- `[jest-mock]` Fix `spyOn` to use `Object.prototype.hasOwnProperty` [#11721](https://github.com/facebook/jest/pull/11721)

packages/jest-each/src/__tests__/template.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ describe('jest-each', () => {
7070
expect(testCallBack).not.toHaveBeenCalled();
7171
});
7272

73+
test('does not throw error when there are multibyte characters in first column headings', () => {
74+
const globalTestMocks = getGlobalTestMocks();
75+
const eachObject = each.withGlobal(globalTestMocks)`
76+
ʅ(ツ)ʃ | b | expected
77+
${1} | ${1} | ${2}
78+
`;
79+
const testFunction = get(eachObject, keyPath);
80+
const testCallBack = jest.fn();
81+
testFunction('accept multibyte characters', testCallBack);
82+
83+
const globalMock = get(globalTestMocks, keyPath);
84+
85+
expect(() => globalMock.mock.calls[0][1]()).not.toThrowError();
86+
expect(testCallBack).toHaveBeenCalledWith({
87+
b: 1,
88+
expected: 2,
89+
'ʅ(ツ)ʃ': 1,
90+
});
91+
});
92+
7393
test('throws error when there are additional words in second column heading', () => {
7494
const globalTestMocks = getGlobalTestMocks();
7595
const eachObject = each.withGlobal(globalTestMocks)`
@@ -88,6 +108,26 @@ describe('jest-each', () => {
88108
expect(testCallBack).not.toHaveBeenCalled();
89109
});
90110

111+
test('does not throw error when there are multibyte characters in second column headings', () => {
112+
const globalTestMocks = getGlobalTestMocks();
113+
const eachObject = each.withGlobal(globalTestMocks)`
114+
a | ☝(ʕ⊙ḕ⊙ʔ)☝ | expected
115+
${1} | ${1} | ${2}
116+
`;
117+
const testFunction = get(eachObject, keyPath);
118+
const testCallBack = jest.fn();
119+
testFunction('accept multibyte characters', testCallBack);
120+
121+
const globalMock = get(globalTestMocks, keyPath);
122+
123+
expect(() => globalMock.mock.calls[0][1]()).not.toThrowError();
124+
expect(testCallBack).toHaveBeenCalledWith({
125+
a: 1,
126+
expected: 2,
127+
'☝(ʕ⊙ḕ⊙ʔ)☝': 1,
128+
});
129+
});
130+
91131
test('throws error when there are additional words in last column heading', () => {
92132
const globalTestMocks = getGlobalTestMocks();
93133
const eachObject = each.withGlobal(globalTestMocks)`
@@ -106,6 +146,26 @@ describe('jest-each', () => {
106146
expect(testCallBack).not.toHaveBeenCalled();
107147
});
108148

149+
test('does not throw error when there are multibyte characters in last column headings', () => {
150+
const globalTestMocks = getGlobalTestMocks();
151+
const eachObject = each.withGlobal(globalTestMocks)`
152+
a | b | (๑ఠ‿ఠ๑)<expected
153+
${1} | ${1} | ${2}
154+
`;
155+
const testFunction = get(eachObject, keyPath);
156+
const testCallBack = jest.fn();
157+
testFunction('accept multibyte characters', testCallBack);
158+
159+
const globalMock = get(globalTestMocks, keyPath);
160+
161+
expect(() => globalMock.mock.calls[0][1]()).not.toThrowError();
162+
expect(testCallBack).toHaveBeenCalledWith({
163+
'(๑ఠ‿ఠ๑)<expected': 2,
164+
a: 1,
165+
b: 1,
166+
});
167+
});
168+
109169
test('does not throw error when there is additional words in template after heading row', () => {
110170
const globalTestMocks = getGlobalTestMocks();
111171
const eachObject = each.withGlobal(globalTestMocks)`

packages/jest-each/src/validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const pluralize = (word: string, count: number) =>
7777

7878
const START_OF_LINE = '^';
7979
const NEWLINE = '\\n';
80-
const HEADING = '\\s*\\w+\\s*';
80+
const HEADING = '\\s*[^\\s]+\\s*';
8181
const PIPE = '\\|';
8282
const REPEATABLE_HEADING = `(${PIPE}${HEADING})*`;
8383
const HEADINGS_FORMAT = new RegExp(

0 commit comments

Comments
 (0)