Reputation: 747
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
Upvotes: 15
Views: 22535
Reputation: 281646
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
const extractDataFromXML = jest.fn(() => ([{ applyodata:[0], liquidoption:[0]}]));
const extractDataFromXML = jest.fn();
extractDataFromXML.mockReturnValue([{ applyodata:[0], liquidoption:[0]}]);
Upvotes: 28