I am getting the error TypeError: _loginViewModel.LoginViewModel.mockReturnValue is not a function
Here is my setup/ Its a typescript project.
import React from 'react';import renderer from 'react-test-renderer';import LoginView from '../src/views/loginView/loginView';import { LoginStatus, LoginViewModel } from '../src/viewModels/loginViewModel';// const mockLoginViewModel = LoginViewModel as jest.Mock;jest.mock('../src/viewModels/loginViewModel', () => ({ LoginViewModel: jest.fn(), // require the actual real modules for the rest of the code ...jest.requireActual('../src/viewModels/loginViewModel'),}));it('renders correctly', () => { (LoginViewModel as jest.Mock).mockReturnValue({ email: 'test@gmail.com', setEmail: jest.fn(), setEmailValid: jest.fn(), password: 'test', setPassword: jest.fn(), setPasswordValid: jest.fn(), rememberMeEnabled: false, alwaysShowInputValid: false, initalLoadRememberMe: jest.fn(), setRememberMe: jest.fn(), onLoginPressed: jest.fn(), navigation: jest.fn(), loginStatus: LoginStatus.idle, showLoginErrorText: false, loginErrorText: '', }); const tree = renderer.create(<LoginView />).toJSON(); expect(tree).toMatchSnapshot();});
Ive tried using a jestSetup.ts file as well but I get the same error.
full error
yarn run v1.22.18$ export NODE_ENV=development && jest --detectOpenHandles --forceExit FAIL tests/loginView.test.tsx● renders correctly TypeError: _loginViewModel.LoginViewModel.mockReturnValue is not a function 13 | 14 | it('renders correctly', () => {> 15 | (LoginViewModel as jest.Mock).mockReturnValue({ | ^ 16 | email: 'test@gmail.com', 17 | setEmail: jest.fn(), 18 | setEmailValid: jest.fn(), at Object.mockReturnValue (tests/loginView.test.tsx:15:33)
What can I do here?