Questions tagged [jest-mock-extended]
16 questions
15
votes
1 answer
Typescript circular reference when testing prisma with jest-mock-extended
I started writting tests revolving around prisma(v3.6.0) usage in my application.
To do so I followed the official prisma page Unit testing with prisma and I am using jest-mock-extended.
My issue is that I have a typescript error when using the…

Yabada
- 1,728
- 1
- 15
- 36
4
votes
1 answer
prisma 2 testing -- TypeError: Cannot read property '_isMockObject' of undefined
I'm trying to set up my testing environment using the Prisma docs and it's been a bit of a trainwreck. So, I'm working backward trying to figure out why it's not working. I have the setup of the singleton.ts file shown below, and when I try initiate…

kevin
- 2,707
- 4
- 26
- 58
2
votes
1 answer
When I test a mock of a submit handler with two functions in it, why doesn't the second function get called?
I have a submit handler in a React form component that does the following onSubmit:
registerForm/index.js
import { loginFunction, registerFunction } from "../../actions";
//within registerform function
const handleSubmit = async(e) => {
…

Franklyn Asafo-Adjei
- 21
- 2
2
votes
1 answer
jest-mock-extended - call mock with object input [Typescript]
I'm using jest-mock-extended in my tests.
I would like to test the following code:
class A {
constructor(private b: B){}
public test(x: string): string {
const res1 = this.b.compose({
name: x + '_foo'
})
const res2 =…

forhas
- 11,551
- 21
- 77
- 111
1
vote
0 answers
How to write test case for react native redux and persist using just
I am writing test case for react native functional component application I am facing issue for redux and persist mocking
mock the redux and persist data in react native application
import React from 'react';
import Header from './Header';
import {…

silambarasan M
- 11
- 2
1
vote
0 answers
How to write unit tests for http server upgrade and handle connection to websocket server?
I have following class and methods -
//A.ts
export abstract class A { }
// B.ts
import http from 'http';
import { Socket } from 'net';
import url, { URL } from 'url';
import { Server as WebSocketServer } from 'ws';
import { authenticateToken } from…

preadeep xsy
- 11
- 3
1
vote
1 answer
Trouble Writing to Jest Mocked Prisma Database
I have two databases that I need to interact with in my code. I have a simple function that takes an object and writes it to my PostgreSQL database using Prisma. I've tested the function with Postman, and it works perfectly, but when I try to…

autoboxer
- 1,358
- 1
- 16
- 37
0
votes
1 answer
Why are my Prisma unit tests calling my database
I have written a unit test for a function that creates data in my database. I created the test based on the Unit testing with Prisma guide and, according to the guide, mocking the Prisma client should prevent calls to my database. When I run the…

Chad
- 11
- 1
- 2
0
votes
0 answers
Exclude mock from resetting
I have a function:
import { mock } from 'jest-mock-extended';
export const createLoggerMock = (): ILogger => {
const logger = mock();
const setup = () => {
logger.error.mockImplementation((...params) => new…

tdranv
- 1,140
- 11
- 38
0
votes
0 answers
jest-mock-extended set property to undefined
Hi is to possible to set a mocked property to undefined somehow?
Interface I want to mock:
export interface IEmail {
from: string | undefined;
body: string;
to: string;
}
Code I want to test:
async function sendEmail(emailData: IEmail):…

Hugo
- 135
- 2
- 9
0
votes
1 answer
Mock reassigning properties in mocked interface
I have the following interface which I'm trying to mock:
export interface IEmail {
from: string;
body: string;
to: string;
}
This interface is used in a function like:
async function sendEmail(emailData: IEmail): Promise {
await…

Hugo
- 135
- 2
- 9
0
votes
1 answer
Jest: Mock a nested function which returns key/value pairs multiple times
I am writing a test for an API which calls a nested api multiple times to get a key value pair. The value will always be a boolean and I am trying to mock this service aka KeyValueService in the code below. These and other more booleans are used in…

Ahmed
- 2,966
- 7
- 42
- 69
0
votes
1 answer
Observable.of mock interface implementation from jest-mock-extend doen't fire
By writing complex mocks I realized, that an Observable.of mock interface implementation with jest-mock-extend doesn't fire. The following test fail with timeout, cause the Observable never fires.
import { mock } from 'jest-mock-extended';
import {…

Zsolt
- 61
- 3
0
votes
1 answer
Error: Uncaught [TypeError:default is not a constructor] jest mock
I have a service class FooService.js which I'm using in my component
export default class FooService {
saveInfo = (params) => {
//method implementation here.
};
}
I'm using this in my component Foo.tsx in saveData method as below:
const…

Sachidananda Naik
- 151
- 2
- 5
- 17
0
votes
1 answer
Inject mocked dependency into mocked constructor
How can I mock the return value of _SqsService.getSqsQueueURL? This compiles, but the function returns undefined. Do I need to inject sqsMocked into sqsServiceMocked? If so,…

Hoppe
- 6,508
- 17
- 60
- 114