Trying to run an unit test for the following : using REACT JS - Jest and enzyme here is part of the code:
componentDidMount () {
let requestSettings = this.props.getViewRequestSettings()
let linkerDefinition = requestSettings.catalog[0].resolvedtemplate[0]
if(linkerDefinition.includes('Universal')){
let functionName =
linkerDefinition.substr(0,linkerDefinition.indexOf('('));
Unit test Files : i have all the props set but not sure if its correct
TypeError: specificMockImpl.apply is not a function
Calling the props:
// jest mock functions (mocks this.props.func)
const getViewRequestSettings = jest.fn([{requestSettings :{catalog:[0],
resolvedtemplate:[0]}}]);
// defining this.props
const baseProps = {
getViewRequestSettings,
ERROR: const getViewRequestSettings = jest.fn([{requestSettings :{catalog:[0], resolvedtemplate:[0]}}]); NOT SURE HOW TO SET UP CORRECTLY
Passing the parameter to jest.fn doesn't return that value when the function is called in your code. Either mock the implementation or mock the return value
Mock implementation
const extractDataFromXML = jest.fn(() => ([{ applyodata:[0], liquidoption:[0]}]));
Mock Return value
const extractDataFromXML = jest.fn();
extractDataFromXML.mockReturnValue([{ applyodata:[0], liquidoption:[0]}]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With