Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setMethods is deprecated and will be removed in future releases

I am using the function setMethods, it is still working, however I received the above message on the console. I am wondering what should be the new approach?.

It is being used to spy on a method and then see if it was called with the mocked parameters, here is the code:

const spyGenerateCalendar = jest.spyOn(wrapper.vm, 'generateCalendar');
const spyAxiosRequest = jest.spyOn(axios, 'get');

// setting methods for spying
wrapper.setMethods({generateCalendar: spyGenerateCalendar});

wrapper.vm.generateCalendar();

// Expecting calls
expect(spyGenerateCalendar).toHaveBeenCalled();
expect(spyAxiosRequest).toBeCalledWith(axiosRequestURL, axiosRequestParams);
like image 759
MaynorSong Avatar asked Oct 30 '25 11:10

MaynorSong


1 Answers

It is unneeded. I am already spying on the method "generateCalendar" on the line:

  const spyGenerateCalendar = jest.spyOn(wrapper.vm, 'generateCalendar');

So If the line wrapper.setMethods({generateCalendar: spyGenerateCalendar}); is removed. The result will be the same, so expect(spyGenerateCalendar).toHaveBeenCalled(); will be true

like image 183
MaynorSong Avatar answered Nov 02 '25 14:11

MaynorSong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!