any idea how to mock an “import” for testing? I use jest now.
ie:
//browser.js
export const browser = {
id: undefined
};
export const getBrowser = function() {
return browser;
};
//fetch-data.js
//code that uses the browser and I wanna test
import {getBrowser} from './../components/browser';
export const fetchData = function() {
const browser = getBrowser();
return Object.assign({dontcare:1}, browser);
};
//My test... Im using jest
import {fetchData} from './../fetch-data.js';
expect(fetchData()).toBe({......});
};
now in the test file I want to mock the response of the browser
component…
Any ideas?
Thanks!
Aucun commentaire:
Enregistrer un commentaire