Category : mocking

I’m looking to mock an axios call, but every time I do I get the mock return value as {}. I’ve tried to isolate just the axios.get and it seems that it’s not mocking the output correctly. Expected: ObjectContaining {"data": "mocked expected"} Received: {} Axios.test.js const axios = require(‘axios’); jest.mock(‘axios’) it("fetches data", async () => ..

Read more

I am using msw to mock fetch API request in my project, I check the network tab and the mockServiceWorker.js resource remains in a"pending" status, additionally, the response retrieves index.html instead of the JSON response I mock in the handlers file. Maybe I am incurring a silly error but I didn’t find some resource on ..

Read more

I’d like to know if it’s possible to mock axios requests with different values depending on url. I use jest and typescript. Now I have this working example: import axios from ‘axios’; import { mocked } from ‘ts-jest’; jest.mock(‘axios’); const mAxios = mocked(axios, true); mAxios.get.mockResolvedValue({ data: [ { id: 1, title: ‘john doe’, }, { ..

Read more

I have tests and I want to redefine Promise like my own function. But when I try to do it I get Promise like undefined. I can’t realize how fix that. My test block: const data = ‘server template’; const PromiseCorrect = Promise; const PromiseMock = { lol: 12 }; Object.defineProperty(window, ‘Promise’, PromiseMock); const file ..

Read more

I am new to Jest and trying to wrap my head around this testing framework. My problem is understanding about the behaviour of es6 class mocking inside an asynchronous code. Example i have an exported class like this: //util_tests.ts export default class Utils{ getMemberAccounts = (): Promise<Number> => new Promise((resolve, reject) => resolve(5)); } and ..

Read more