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.

`no-useless-undefined`: `undefined` removed from jest function matchers

See original GitHub issue
test('function called with different parameters that could be undefined', () => {
	expect(someFunction).toHaveBeenCalledWith(1, 2, 3);
	expect(someFunction).toHaveBeenCalledWith(1, undefined, 3);
	expect(someFunction).toHaveBeenCalledWith(1, 2, undefined);
});

This is breaking as jest toHaveBeenCalledWith (and other similar matchers) explicitly checks for nth argument to be undefined

Would be better if this rule would accept and array of “acceptable” functions that have undefined?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

2reactions
silverwindcommented, Aug 27, 2020

Essentially it’s a unsolvable problem but I guess a allowlist of common usages of undefined is a bandaid fix that might ease the pain in some cases. Still I have the rule disabled and would not recommend enabling it 😉.

1reaction
fiskercommented, Aug 27, 2020

Yap, the simplest way to fix this is add this name to that list.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-useless-undefined - should not be fixable #760 - GitHub
As it stands, the rule corrects console.log(undefined) to console.log(). ... no-useless-undefined : undefined removed from jest function ...
Read more >
Jest Mock returns undefined instead of value - Stack Overflow
I am trying to mock a function from other dependency. The function from dependency should return an array, but it is showing undefined...
Read more >
Checking for null and undefined - Testing React Apps with ...
The unhappy path for this function returns undefined . In data.getCompany.test.js, add a test for the getCompany unhappy path using the toBeUndefined matcher....
Read more >
sindresorhus/eslint-plugin-unicorn (Raised $2856.00)
`no-useless-undefined`: `undefined` removed from jest function matchers. Unfunded#807created bydanut-t. $0.00. Rule proposal: `no-native-addon-dependencies`.
Read more >
@cling/eslint-config - npm
ESLint configuration for @cling related packages. Latest version: 1.7.0, last published: a year ago. Start using @cling/eslint-config in ...
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