Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions packages/jest-each/src/__tests__/array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ describe('jest-each', () => {
],
]);
const testFunction = get(eachObject, keyPath);
testFunction('expected string: %s %d %s %s %d %j %s %j %d %d', noop);
testFunction('expected string: %s %d %s %s %d %j %s %j %d %d %#', noop);

const globalMock = get(globalTestMocks, keyPath);
expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
`expected string: hello 1 null undefined 1.2 ${JSON.stringify({
foo: 'bar',
})} () => {} [] Infinity NaN`,
})} () => {} [] Infinity NaN 0`,
expectFunction,
);
expect(globalMock).toHaveBeenCalledWith(
`expected string: world 1 null undefined 1.2 ${JSON.stringify({
baz: 'qux',
})} () => {} [] Infinity NaN`,
})} () => {} [] Infinity NaN 1`,
expectFunction,
);
});
Expand Down
16 changes: 8 additions & 8 deletions packages/jest-each/src/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ const EXPECTED_COLOR = chalk.green;
const RECEIVED_COLOR = chalk.red;
const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp%]/g;
const PRETTY_PLACEHOLDER = '%p';
const INDEX_PLACEHOLDER = '%#';

export default (cb: Function) => (...args: any) =>
function eachBind(title: string, test: Function): void {
if (args.length === 1) {
const table: Table = args[0].every(Array.isArray)
? args[0]
: args[0].map(entry => [entry]);
return table.forEach(row =>
cb(arrayFormat(title, ...row), applyRestParams(row, test)),
return table.forEach((row, i) =>
cb(arrayFormat(title, i, ...row), applyRestParams(row, test)),
);
}

Expand Down Expand Up @@ -76,7 +77,7 @@ const getPrettyIndexes = placeholders =>
[],
);

const arrayFormat = (title, ...args) => {
const arrayFormat = (title, rowIndex, ...args) => {
const placeholders = title.match(SUPPORTED_PLACEHOLDERS) || [];
const prettyIndexes = getPrettyIndexes(placeholders);

Expand All @@ -85,16 +86,15 @@ const arrayFormat = (title, ...args) => {
if (prettyIndexes.indexOf(index) !== -1) {
return {
args: acc.args,
title: acc.title.replace(
PRETTY_PLACEHOLDER,
pretty(arg, {maxDepth: 1, min: true}),
),
title: acc.title
.replace(PRETTY_PLACEHOLDER, pretty(arg, {maxDepth: 1, min: true}))
.replace(INDEX_PLACEHOLDER, `${rowIndex}`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this and line 97 can move outside of the reduce and just do a replace on the prettyTitle returned before calling util.format on line 103.

Maybe something like:

return util.format(
    prettyTitle.replace(INDEX_PLACEHOLDER, rowIndex.toString()),
    ...remainingArgs.slice(0, placeholders.length - prettyIndexes.length),
  );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfix22 anything preventing us from applying this solution? Seems more generic approach

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh i missed this. I'll take a look.

};
}

return {
args: acc.args.concat([arg]),
title: acc.title,
title: acc.title.replace(INDEX_PLACEHOLDER, `${rowIndex}`),
};
},
{args: [], title},
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-23.0/WatchPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MyWatchPlugin {
## Hooking into Jest

To connect your watch plugin to Jest, add its path under `watchPlugins` in your Jest configuration:

```javascript
// jest.config.js
module.exports = {
Expand Down