首页 > 解决方案 > ReferenceError: windowTopScroll is not defined, when running tests with jest

问题描述

I am trying to run a test on a file where windowTopScroll() is called on mounted method.

Jest is throwing ReferenceError: windowTopScroll is not defined

Here is my code for the test.

import Vue from 'vue';
import sinon from 'sinon'
import WorkTimeline from '../../components/WorkTimeline.vue';
import { createLocalVue, mount, shallowMount } from '@vue/test-utils';

Vue.config.ignoredElements = ['name']
describe("WorkTimeline.test.js", () => {
    const windowTopScroll = jest.fn()
    test('renders WorkTimeline Slider', () => {
        const wrapper = shallowMount(WorkTimeline, {
            mocks: {
                $t: () => {},
                windowTopScroll: jest.fn()
            },

        });
        expect(windowTopScroll).toHaveBeenCalled();



    });

标签: vue.jsjestjsvue-test-utils

解决方案


推荐阅读