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

Feature Request: Throw error if first argument to "it" or "test" is not a string #5493

Closed
reggi opened this issue Feb 7, 2018 · 12 comments
Closed

Comments

@reggi
Copy link

reggi commented Feb 7, 2018

Coming from ava, you don't need test descriptions.

The following would work.

test(() => {
    jest.mock('../config', () => () => {
      return { protocol: 'http', host: 'localhost', port: '9999', pathPrefix: '' }
    })
    const config = require('../config')()
    expect(config.api.port).toBe('9999');
}) 

However, this doesn't do anything in jest.

Can we throw an error if there is no function as the second argument? Or if a string is not passed into the first?

@cpojer
Copy link
Member

cpojer commented Feb 7, 2018

Yeah, do you wanna send a PR to make this throw? :)

@reggi
Copy link
Author

reggi commented Feb 8, 2018

@cpojer I'd love to. Thanks for the feedback.

@brianlmacdonald
Copy link
Contributor

Can I do this?

@reggi
Copy link
Author

reggi commented Feb 11, 2018

@brianmacdonald sure

@brianlmacdonald
Copy link
Contributor

brianlmacdonald commented Feb 12, 2018

@reggi Please correct me if I'm off base, but from what I can tell, jest-Jasmine2 is running 'test' and 'it', and not jest-circus, which, I'm assuming will eventually replace jest-Jasmine2. So should I get the errors to throw in both places? Or just one?

@SimenB
Copy link
Member

SimenB commented Feb 12, 2018

Both would be great!

jest-circus is the eventual replacement for jasmine (jest-jasmine2), but it's currently on the backburner

@SimenB
Copy link
Member

SimenB commented Mar 6, 2018

#5558

@SimenB SimenB closed this as completed Mar 6, 2018
@mike-robertson
Copy link

Can we throw an error if there is no function as the second argument? Or if a string is not passed into the first?

Is it possible to not do this behavior, or at the very least, put the ability to toggle it off?

Maybe my use case isn't common, but I find myself writing out a bunch of test cases first, then I begin implementing them. Getting an error thrown in that scenario clutters up the terminal with errors about "Missing second argument. It must be a callback function".

Thanks!

@javorosas
Copy link

I agree with @mike-robertson. It's super common in TDD to write the specs first and then implement the behavior. I don't know how this change went through. I'll open a separate issue.

@elyobo
Copy link

elyobo commented Jun 13, 2018

Ditto what @mike-robertson said; the missing second function is (was) a deliberate feature to allow skipped tests and I use it in exactly the way that he describes, writing out test cases to be written as I think about it and filling them in later. It seems that #5558 should have checked that the first arg was a string rather than checking that two args were passed...

@domharrington
Copy link

Workaround for this now is to pass in an empty function in addition to .skip().

Previously I could do:

test('Test to be written')

But that throws now, so I have to do:

test.skip('Test to be written', () => {})

Which works, but seems much more verbose. Was this intentional?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants