samedi 14 novembre 2020

Jest mocking module that exports a class and functions

I have a module that exports a class and 2 functions and that module is imported into a file that is being tested.

someFile.js
const {theclass, thefunction} = require("theModule");

const getSomeFileData = () => {
   let obj = new theclass();
   //some logic
   return obj.getData();
}

In the test file, I want to mock the module "theModule" and return a known value when the function obj.getData() is called. How would I go about mocking this module("theModule") when testing file "someFile.js"?

Aucun commentaire:

Enregistrer un commentaire