question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
mike-robertsoncommented, Mar 23, 2018

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!

3reactions
elyobocommented, 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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to test the type of a thrown exception in Jest
From my (albeit limited) exposure to Jest, I have found that expect().toThrow() is suitable if you want to only test an error is...
Read more >
try...catch - JavaScript - MDN Web Docs - Mozilla
The code in the try block is executed first, and if it throws an exception, the code in the catch block will be...
Read more >
API Reference | Vitest
For example, this code asserts that an input value is not equal to 2 . If it's equal, assertion will throw an error,...
Read more >
User's Manual: Functions and Variables - Apache JMeter
If an undefined function or variable is referenced, JMeter does not report/log an error ... String, TestPlanName, Return name of current test plan,...
Read more >
Programming FAQ — Python 3.11.1 documentation
What is the difference between arguments and parameters? ... Why does a_tuple[i] += ['item'] raise an exception when the addition works?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found