Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jest-each] Relaxed the validation to allow multibyte characters in headings #11575

Merged
merged 4 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 60 additions & 0 deletions packages/jest-each/src/__tests__/template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand All @@ -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)`
Expand All @@ -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)`
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down