0

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();



    });
skyboyer
  • 22,209
  • 7
  • 57
  • 64
  • 1
    This might not be the problem but i notice that you do not send in your variabel windowTopScroll declared above the test. You simply send in an object called windowTopScroll that you set to jest.fn(). And therefore expect(windowTopScroll).toHaveBeenCalled(); will always fail. – Achtung Aug 06 '19 at 12:41
  • @Achtung, nice catch! could you compose official answer? – skyboyer Aug 06 '19 at 12:54
  • @skyboyer I suspect it wont solve the problem. This bug shouldnt result in windowTopScroll being undefined. – Achtung Aug 06 '19 at 12:58
  • @Achtung thank you for the quick response. Didn't solve the problem by adding it to top of the test. A general question - there are many other functions in mounted function in my other files too, how to deal with these reference errors? How to let jest know that the function is available? – karthik sista Aug 07 '19 at 06:22

0 Answers0