相关疑难解决方法(0)

Jest 测试(ReferenceError: google is not defined)ReactJS 和 Google Charts

在此处输入图片说明

我正在使用他们 CDN 中的 google script 标签(尝试过身体和头部) <script src="https://wikitags.com/js/googlecharts.min.js"></script>

我的应用程序中的 Google Chart 工作正常,但是它导致我的 Jest 测试失败......


里面的 <ChartComponent />

componentDidMount() {
    // Load the Visualization API and the corechart package.
    console.log('Chart mounted');
    google.charts.load('current', { packages: ['corechart', 'line'] });
    google.charts.setOnLoadCallback(this.getSocialData({ days: this.state.days }));
}
Run Code Online (Sandbox Code Playgroud)

有没有简单的方法来解决这个问题?


我试过的

import React from 'react'
import { mount, shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
import Trends from './Trends'
import Chart from '../entity/Chart'
const body = { subject: { id: 0 } };
const TrendComponent = shallow(<Trends …
Run Code Online (Sandbox Code Playgroud)

javascript google-visualization reactjs jestjs enzyme

3
推荐指数
1
解决办法
2845
查看次数