I want to know If I can test the properties that are added to dataFunc function.
This is what I want to test:
buttonData - check that it is actually a button and not some other element.
url - this param can be a function like this: (url) => url.replace('##a##', 'sometext')
dimensions - this is an object that looks like this: { width: 100, height: 200 }
I am not looking for someone to solve this for me, just to point me in the right direction.
This is the function:
auth( buttonData, url, dimensions ){
return new Promise((resolve, reject) => {
const success = (e, data) => {
resolve({data, error: null});
};
const error = () => {
resolve({data: null, error: 'Error'});
};
jQuery(buttonData).dataFunc({
success,
error,
url,
dimensions
});
});
}
I know I can do it using toHaveBeenCalledWith but I do not understand how to mock the params I mentioned earlier in the jquery func.
How can I mock jQuery(buttonData).dataFunc params url amd dimensions?
I have managed to mock success using the following code:
global.jQuery = () => {
return {
dataFunc: ({success, error}) => {
success(jest.fn(), {access_level: 0})
},
};
};
But I have trouble testing the params I mentioned at the top.