Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: specificMockImpl.apply is not a function

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

like image 603
user 9191 Avatar asked Feb 06 '19 16:02

user 9191


1 Answers

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]}]);
like image 155
Shubham Khatri Avatar answered Nov 14 '22 01:11

Shubham Khatri