Skip to content

Commit

Permalink
[jest-each] Relaxed the validation to allow multibyte characters in h…
Browse files Browse the repository at this point in the history
…eadings (#11575)
  • Loading branch information
hnisiji committed Aug 27, 2021
1 parent d455d2d commit 499ef4f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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

0 comments on commit 499ef4f

Please sign in to comment.