-
-
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
Jest should mark test as 'skipped' if empty function is provided as second argument #2584
Comments
Let's discuss this topic in this issue: #2209 since it refers to the same problem, but with different solutions. |
@thymikee That's a very different issue. Handling empty functions is unrelated to handling functions with no assertions. Can this be re-opened? I write lots of tests like this which have no assertions but I certainly don't want to fail or skip where I'm just making sure the code doesn't throw: it('renders without crashing', () => {
mount(<Counter />)
}) |
You shouldn't rely on this behaviour, use |
Reopening this so it can be discussed further. |
@thymikee I started writing some tests w/o assertions because create-react-app does & @gaearon recommended it on Twitter, you might want to create a relevant issue inside create-react-app to discuss. Wasn't aware Happy to create a PR for this issue FYI |
@cpojer what do you think? |
I wasn’t aware of that, and Create React App has shipped for many versions with test cases that rely on crash failing the test. Is this no longer how it works? Why? Do we need to tell thousands of users to change their test cases? Since which version of Jest has this behavior changed? |
Oh, I missed the discussion in #2209, sorry. I got the impression that this wasn't implemented. |
@gaearon cool, nothing has changed 😄. What I mean is that the behaviour of empty tests or tests without expects may change in the future. As for #2209 wasn't implemented and is still discussed. |
Now as I look at this, I like simpler approach of CRA better than |
Thanks for clarifying! |
@ashtonsix I understand your confusion around the behavior change we made to make tests without a provided function skipped but I don't think we should make it so empty functions are skipped based on the source. It doesn't seem like a reliable method especially when we have an officially supported way for it. I'm sorry you got confused by the feature we added:
Also, we will always support tests that simply throw. They will turn into a failing test. |
With the 21 update tests as this will be skipped in jest: ○ <<<< General Tests >>>> |
Somehow this discussion got derailed. The request is to have a way to add pending specs without an implementation. That way we can add specs first, then implementations. Ideally, these pending specs would actually appear as "pending". But "skipped" would be sufficient. This supports actual TDD process. Today, the following: it('does not show the Cancel button'); results in the error "Missing second argument. It must be a callback function." Like I said, this supports TDD, and is implemented in other testing frameworks. For example, rspec. Passing an "empty function" as the second parameter might be a better developer experience, but is not necessary to implement "pending implementation" examples. |
Jest 24 will come with Install |
This is a feature
Background, current behavior & proposed behavior
When planning tests I would often write code like this:
Until a recent release these examples would crash, I started supplying an empty function as a work-around like so (& expect others do also for various reasons):
it('updates the value', () => {})
Using the latest version of Jest both examples will work, the difference is the first example will create 2 skipped tests & the second example will create a passed test. I believe the tests should be skipped in both cases. Example logic for this might look like:
Using
Windows 7, Jest 17
The text was updated successfully, but these errors were encountered: