eslint-plugin-jest
eslint-plugin-jest copied to clipboard
[new rule] prefer `.not.toHaveBeenCalled()` over `toHaveBeenCalledTimes(0)`
// instead of
expect(testSpy).toHaveBeenCalledTimes(0)
// prefer
expect(testSpy).not.toHaveBeenCalled()
// unaffected
expect(testSpy).toHaveBeenCalledTimes(1)
expect(testSpy).not.toHaveBeenCalledTimes(5)
~Could you please provide a description of what you'd like, including examples of correct and incorrect code that this rule would check?~ thanks!
I'm not sure if enough of a clear gain here to make it worth having a whole new rule for this (the failure message is very similar, and it could be more consistent depending on the surrounding code), given you could use no-restricted-syntax
to enforce this using CallExpression[callee.property.name='toHaveBeenCalledTimes'][arguments.length=1][arguments.0.value=0]
🤔
Reviving this as I'm seeing a lot of areas of this happening within a codebase - would be nice to have an autofixable rule here instead of flagging restricted syntax.