in Education by
I'm trying to mock a TypeScript class with Jest and I'm obviously doing something because receive the following error: error TS2743: No overload expects 1 type arguments, but overloads do exist that expect either 0 or 2 type arguments. This is my code: Foo.ts export default class Foo { bar(): number { return Math.random() } } Foo.test.ts import Foo from './Foo' describe('Foo', () => { it("should pass", () => { const MockFoo = jest.fn(() => ({ bar: jest.fn(() => { return 123 }), })) }) }) The full error: TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option): src/Foo.test.ts:6:29 - error TS2743: No overload expects 1 type arguments, but overloads do exist that expect either 0 or 2 type arguments. 6 const MockFoo = jest.fn(() => ({ ~~~ UPDATE If it is of any relevance, this is my Jest config: module.exports = { moduleFileExtensions: ['ts', 'js'], transform: { '^.+\\.ts$': 'ts-jest', }, testMatch: ['**/src/**/*.test.(ts)'], testEnvironment: 'node', }; JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Jest has the following signature for jest.fn: /** * Creates a mock function. Optionally takes a mock implementation. */ function fn(implementation?: (...args: Y) => T): Mock; So you need to specify the array of types for the args, in your particular case you could just pass an empty array as there are no args in your implementation function. const MockFoo = jest.fn(() => ({

Related questions

0 votes
    I am trying to declare a list which can either be full of type 'a' data or type 'b' at a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I am trying to declare a list which can either be full of type 'a' data or type 'b' at a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Question No. 6 Which of the following module is not used for parsing command line arguments automatically ? O ... argparse O getopt Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    I've set up Angular 2 (RC4) with angular-cli and use [email protected]. I installed jQuery with npm ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    The client expects a timely response from the service and might even block while it waits. This represents the _________ client ... B. One to one C. One to many D. Synchronous...
asked Jan 10, 2023 in Technology by JackTerrance
0 votes
    i'm trying to test with jest this route on my node microservice. At the initalisation of my microservice ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a service with a simple GET method: export class MyService { constructor(private http: HttpClient) { ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Restricted Boltzmann Machine expects the data to be labeled for Training. (a) False (b) True...
asked Oct 20, 2020 in Technology by Editorial Staff
0 votes
    Our core application changed from Python 2.6 to Python 2.7 maybe to Python 3 in later release. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I asked a question like this here: How to adjust Label in tkinter? But the events load up and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Can we overload the constructors?...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    How can I mock the database calls to make my application logic been tested without database? JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    How can I mock the database calls to make my application logic been tested without database? JavaScript ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
...