-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Support the assert module more cleanly #3173
Comments
I'm willing to implement this if I could get some direction. |
This one needs patching our test runner. Which means, we would need to further alter Jasmine code (which is ok I guess, because we're currently rewriting it). So, I would wait for @DmitriiAbramov to weigh in on this before sending a PR. The code you'll likely need to change sits here (be aware that @wtgtybhertgeghgtwtg is going to refactor this module to a class). You'll need to adjust the error and build similar messages to these. Formatting methods like |
I'm working on this right now (just fudging with my local |
Also, when I add a |
Oh, and also |
Oh, please don't do it to yourself! You'll be better of forking Jest and linking it (instructions in CONTRIBUTING.md), because since last release we rewritten our Jasmine fork to be modular. |
HOORAY!!!! Thank you @thymikee, @DmitriiAbramov, and @cpojer! This is going to make my ASTs Workshop soooo much better. Developing the fixer function for ESLint will be much improved. Thank you thank you :) On that note, when's the next scheduled release? 😸 |
@cpojer I think we should start making prereleases (e.g. from master), like Yarn does. |
On board with pre-releases but the next major for Jest may be in a month from now unfortunately. |
Ah, too bad. If I could get a pre-approved release with this that'd be great 😀 |
Anyone aware if that feature is still working? I'm seeing import assert from 'assert' |
@oliviertassinari it should work. we have a snapshot test for these errors. |
I can verify that it works for me. |
Yes, I can try to provide a reproduction, I have also tried to use it with power-assert with no luck (I was curious). |
@oliviertassinari do you mind opening an issue with the repro case? |
I couldn't reproduce it on a simple example. That's just working. I must have something on my project breaking this feature. Thanks for the answer. I'm gonna dig into it. Will eventually use the expect API otherwise. |
@kentcdodds, this is great, thank you! How much time and effort do you think it's gonna require to handle chai assertion errors similarly? Or does it need to be done on the chai side and not jest? Currently what we have with common-js assert: And the thrown objects seem very similar I am also willing to work on this with some direction. I could probably use your #3217 as a reference. |
I expect it would be a matter of slightly modifying the code to support assert. So hopefully pretty straightforward 👍 |
it seems like this whole system should be pluginized, because it can get out of control if we start adding all kind of use cases :) jest.addErrorFormatter(assertFormatter);
jest.addErrorFormatter(chaiFormatter); |
or maybe rather specify it in the config file jest: {
errorFormatters: ['jest-error-formatters-chai', 'jest-error-formatters-assert']
} |
@aaronabramov Yeah, plugins are a nice idea. 👍 |
Whatever happened to this? I'm trying out Jest for the first time, and the biggest pain for me is that when using Mocha + Chai I'd be able to see the actual difference for things like asserting array elements, and IntelliJ would provide me a diff based on the results. In switching to
and error messages that are not even close to the detail I had with Mocha + Chai:
&
From my understanding, the issue lies with Jest not taking any advantage of information provided by Chai (if it's important, I'll try and dig up the Chai issue about this). I think an This is going to be the biggest stopper I think for me to not pick up Jest :) |
We have no special handling of |
Sorry about that! I just saw people talking about I've made #8152 |
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Jest doesn't output a very good message when using
assert.equal
from node's built-inassert
module when you compare it to other testing frameworks like Mocha. This is a problem for me because ESLint's tester uses theassert.equal
for its error messages.What is the expected behavior?
I want it to output the
error.expected
anderror.actual
like Mocha does.Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
I'll do you one better. Here's a repo: https://github.com/kentcdodds/jest-assert
And here's a screenshot:
Reference: eslint/eslint#8173
The text was updated successfully, but these errors were encountered: