'How to check that document.location.assign was called with specific url

I'm testing with jest function what called document.location.assign url with params.

sort: function (type){
  document.location.assign(document.location.pathname + '?' + `&order=${type}-asc`);
},

How to check in jest that document.location.assign was called with specific url?

describe('sort', () => {
global.window = Object.create(window);
const url = "http://localhost:8080/uk/admin/students";
Object.defineProperty(window, 'location', {
    value: {
        href: url
    }
});
test('it calls assign with expected URL',async () => {
    window.location.assign = jest.fn();
    const wrapper = shallowMount(Students)
    await wrapper.find('.sort-by-id').trigger('click')
    await expect(window.location.assign).toHaveBeenCalledWith('/?&order=id-asc')
})

})

error in command line



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source