I have a very complex object i am using to mock out a DataTable() object for the purposes of testing.
const obj = {
DataTable: () => {
return {
columns: () => {
return {
data: () => {
return {
eq: () => {
return {
indexOf: jest.fn(),
};
},
};
},
visible: () => {
return jest.fn();
},
};
},
};
},
};
Inside my testing code I am trying to spy on some of these functions but it always returns undefined. Is there a way to mock out the return value of deeply nested functions?
jest.spyOn(obj.DataTable().columns().data().eq(), 'indexOf').mockReturnValue('test');
console.log(obj.DataTable().columns().data().eq().indexOf()); // returns undefined, should return 'test'