I'm having trouble mocking/testing this load-script package with jest: https://www.npmjs.com/package/load-script
import Footer from './Footer'
import { shallowMount } from '@vue/test-utils'
import { mocks } from '@test/components.spec-helper'
import load from 'load-script'
describe('Footer Component', () => {
const wrapper = shallowMount(PageFooter, { mocks })
jest.spyOn('load-script', 'load')
it('should render the component correctly', () => {
expect(wrapper.html()).toMatchSnapshot()
})
it('should call load function', () => {
expect(load).toHaveBeenCalledWith('mockUrl')
})
Footer.vue
import load from 'load-script'
export default {
name: 'Footer',
mounted () {
load('mockUrl')
},
Error: Cannot spyOn on a primitive value; string given
The main problem seems to be jest won't let me spy on the load method from the 'load-script' package... Not sure what this line should be for it to work:
jest.spyOn('load-script', 'load')
the first argument shouldn't be a string it should be the module as an object, but i'm not sure what it should be when the package is called 'load-script'
jest.mock("load-script")? - jonrsharpejest.spyOn('load-script', 'load')doesn't make sense. You're trying to spy on a string, not an object. Try to spy on*import. Also, there's noloadmethod. It'sdefault. - Estus Flask