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
jest.mock and jest.doMock take an optional generic, representing the return type of the factory. For example,
// The optional type argument provides typings for the module factoryjest.mock<typeofimport('../moduleName')>('../moduleName',()=>{returnjest.fn(()=>42);});
Without specifying typeof import('../moduleName'), Jest's types doesn't know what the module looks like and will allow anything to be returned in the factory.
I'd like to have an ESLint rule to enforce that the generic parameter is used whenever a factory function is used. Jest auto-mocks (no factory) and virtual mocks (no corresponding actual module) don't need to have the generic parameter.
A new rule that requires type-checking.
jest.mock
andjest.doMock
take an optional generic, representing the return type of the factory. For example,Without specifying
typeof import('../moduleName')
, Jest's types doesn't know what the module looks like and will allow anything to be returned in the factory.I'd like to have an ESLint rule to enforce that the generic parameter is used whenever a factory function is used. Jest auto-mocks (no factory) and virtual mocks (no corresponding actual module) don't need to have the generic parameter.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Auto-fixable: Yes
The text was updated successfully, but these errors were encountered: