im writing jest file for a feature, and while coming from Angualr jasmine seems very similar to jest. Im encounter some issue while trying to mock some function in the jest file.
const MMycustomContext= React.createContext({});
export const userActionMenuPopUpBuilder = (action, target, id) => {
const { statePath,breadcrumbers, } = useContext(MMycustomContext);
const [showPopUp, setShowPopUp] = useState(false);
const [itemSelected, setItemSelected] = useState({});
}
And this is my Jest file:
describe('userActionMenuPopUpBuilder ', () => {
it('Should be Truthy', () => {
jest.spyOn(React, 'useContext').mockImplementationOnce(() => {
return {
name: 'this is a mock context return value'
}
})
const temp = userActionMenuPopUpBuilder (mockAction, target, id);
console.log(temp);
expect(temp).toBeTruthy();
});
});
when im running the Jest file, i get exception because useContext is undefined- calling userActionMenuPopUpBuilder function from the jest file, i tried to spyOn and make a mock from useContext like i did above, but it dosent seems to work and i still gets undefined,
Any suggestions?
thanks