You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the rule prefer-to-have-been-called-once, this code...
expect(mySpy).not.toHaveBeenCalledTimes(1);
can be (correctly) autofixed as follows...
expect(mySpy).not.toHaveBeenCalledOnce();
However there seems to be a common misconception that not.toHaveBeenCalledOnce() means the method was never called. I can see that arguably it reads that way (in English), and perhaps for that reason we should not be encouraging not.toHaveBeenCalledOnce().
I have found many instances where people write not.toHaveBeenCalledOnce() when their intent was not.toHaveBeenCalled() or equivalently toHaveBeenCalledTimes(0).
Worse case scenario this potentially leads to false positive test passes.
I'd be pleased to see an option at least to allow the autofix for the negated case to be disabled. I have set my repo up to ban not.toHaveBeenCalledOnce() using jest/no-restricted-matchers, since we found every single instance of this to be a mistake.
The text was updated successfully, but these errors were encountered:
With the rule
prefer-to-have-been-called-once
, this code...can be (correctly) autofixed as follows...
However there seems to be a common misconception that
not.toHaveBeenCalledOnce()
means the method was never called. I can see that arguably it reads that way (in English), and perhaps for that reason we should not be encouragingnot.toHaveBeenCalledOnce()
.I have found many instances where people write
not.toHaveBeenCalledOnce()
when their intent wasnot.toHaveBeenCalled()
or equivalentlytoHaveBeenCalledTimes(0)
.Worse case scenario this potentially leads to false positive test passes.
I'd be pleased to see an option at least to allow the autofix for the negated case to be disabled. I have set my repo up to ban
not.toHaveBeenCalledOnce()
usingjest/no-restricted-matchers
, since we found every single instance of this to be a mistake.The text was updated successfully, but these errors were encountered: