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

scripts/jest/matchers/toWarnDev: Expected and actual arguments to jest-diff are mixed up. #12285

Closed
sompylasar opened this issue Feb 25, 2018 · 0 comments

Comments

@sompylasar
Copy link
Contributor

Do you want to request a feature or report a bug?

bug

What is the current behavior?

toWarnDev calls jestDiff(a, b) as jestDiff(normalizedMessage, expectedMessages[0]) and jestDiff([normalizedMessage], expectedMessages):

} else if (expectedMessages.length === 1) {
errorMessage =
'Unexpected warning recorded: ' +
jestDiff(normalizedMessage, expectedMessages[0]);
} else {
errorMessage =
'Unexpected warning recorded: ' +
jestDiff([normalizedMessage], expectedMessages);
}

jestDiff(a, b) calls diffStrings(a, b) where by default a is annotated as 'Expected' (green), b as 'Received' (red).

https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/diff_strings.js#L86-L90

const getAnnotation = (options: ?DiffOptions): string =>
  chalk.green('- ' + ((options && options.aAnnotation) || 'Expected')) +
  '\n' +
  chalk.red('+ ' + ((options && options.bAnnotation) || 'Received')) +
  '\n\n';

What is the expected behavior?

toWarnDev should pass the expected values into a, the actual (received) values into b of jestDiff:

jestDiff(expectedMessages[0], normalizedMessage)
jestDiff(expectedMessages, [normalizedMessage])
sompylasar added a commit to sompylasar/react that referenced this issue Feb 26, 2018
…ebook#12285)

`toWarnDev` calls `jestDiff(a, b)` which calls `diffStrings(a, b)` where by default `a` is annotated as `'Expected'` (green), `b` as `'Received'` (red).

So the first argument passed into `jestDiff` should be the expected message, the second should be the actual message.
It was vice versa previously.

- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/index.js#L54
- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/index.js#L93
- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/diff_strings.js#L249-L251
sompylasar added a commit to sompylasar/react that referenced this issue May 22, 2018
…ebook#12285)

`toWarnDev` calls `jestDiff(a, b)` which calls `diffStrings(a, b)` where by default `a` is annotated as `'Expected'` (green), `b` as `'Received'` (red).

So the first argument passed into `jestDiff` should be the expected message, the second should be the actual message.
It was vice versa previously.

- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/index.js#L54
- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/index.js#L93
- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/diff_strings.js#L249-L251
sompylasar added a commit to sompylasar/react that referenced this issue Jun 8, 2018
…ebook#12285)

`toWarnDev` calls `jestDiff(a, b)` which calls `diffStrings(a, b)` where by default `a` is annotated as `'Expected'` (green), `b` as `'Received'` (red).

So the first argument passed into `jestDiff` should be the expected message, the second should be the actual message.
It was vice versa previously.

- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/index.js#L54
- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/index.js#L93
- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/diff_strings.js#L249-L251
gaearon pushed a commit that referenced this issue Jun 8, 2018
) (#12288)

`toWarnDev` calls `jestDiff(a, b)` which calls `diffStrings(a, b)` where by default `a` is annotated as `'Expected'` (green), `b` as `'Received'` (red).

So the first argument passed into `jestDiff` should be the expected message, the second should be the actual message.
It was vice versa previously.

- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/index.js#L54
- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/index.js#L93
- https://github.com/facebook/jest/blob/457776b2889a9be1ce8a2c636a23417264a98d99/packages/jest-diff/src/diff_strings.js#L249-L251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant