您似乎关注了这些文档 正在加载 Maps JavaScript API
// Create the script tag, set the appropriate attributes
var script = document.createElement('script');
script.src = 'https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap';
script.async = true;
// Attach your callback function to the `window` object
window.initMap = function() {
// JS API is loaded and available
};
// Append the 'script' element to 'head'
document.head.appendChild(script);
要在赛普拉斯组件测试中复制,对赛普拉斯应用程序窗口/文档做类似的事情
(没有尝试过这个)
const win = cy.state('window')
const document = win.document
var script = document.createElement('script');
script.src = 'https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap';
script.async = true;
document.head.appendChild(script);
// use attachTo option to put your component in correct context
// i.e where google maps is global
const wrapper = mount(MyComponent, {
attachTo: win
})