Jest Unit Testing function that calls a second one that returns a promise

Edited Question with vazsonyidl suggestions applied I have to write unit tests for a function similar to this one: import {External} from ‘ExternalModule’; async functionA(){ this.functionB()….

mock post method npm request module with jest

I know that npm request module is now deprecated, but i want to mock a post http call with jest. Here is my function import { post } from ‘request’; export functionToFetch(uriFetching) { return …

TypeError: jwt(…).unless is not a function when mocking with Jest

I am trying to mock the .unless function of express-jwt and currently have this mock setup to compare a JWT with an admin and non admin. This worked perfect until we added .unless and I am not sure …

TypeError: nock(…).persist(…).log is not a function

I am trying to get more info on why my nock mock is not right, but I can’t make the persist().log() work. Here is the test : it(“should delete online absentee bid given its id”, () => { …

Testing Cross Browser Extension With Jest, How To Mock Chrome Storage API?

After putting off testing for a while now due to Cypress not allowing visiting chrome:// urls, I decided to finally understand how to unit/integration test my extension – TabMerger. This comes after …

JEST | Assert a function was called inside addEventListener callback

I have the following function: Code to test export default function main() {     const createAndAppendPTag = () => {         const p = document.createElement(‘p’);         document.body.appendChild(…

Unit test with react hook fails

I don’t understand the result I get on this unit test. I expect the second check for textField.valid to be true and instead it returns false. Below is part of the component I’m testing against: export …

Test clearing of search input field on submit (after fetching)

I want to test that a search box does calls a handler (passed as prop) with the fetched results and resets the input field afterwards. import React, { useState } from ‘react’ import Axios from ‘axios’ …

Mocking node_modules which return a function with Jest?

I am writing a typeScript program which hits an external API. In the process of writing tests for this program, I have been unable to correctly mock-out the dependency on the external API in a way …

Jest Unit test + received undefined

I am using Jest as my unit test framework. I am trying to mock third part npm “request” and executed my test cases, but i am receiving and the test fails expect(jest.fn())….