vue.js - 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();
});
解决方案
推荐阅读
- azure - 如何以编程方式创建 CosmosDB 用户定义函数
- batch-file - PXF 证书不会安装 -dump 命令成功完成
- ruby-on-rails - 如何从 gmail api 检索和保存消息详细信息
- javascript - 如何在 Spark AR 脚本中监控脉冲值?
- r - 如何将字符串与R中的数字分开?
- java - android recyclerview 未在首次启动时加载
- reactjs - 如何将 React 应用程序中的 txt 文件保存到 SilverStripe 4 后端?
- java - java中2d赛车游戏中涉及道路的图形
- java - Spring boot - 以交互模式运行集成测试
- python - 使用 TensorFlow 移动梯度