admin管理员组文章数量:1123948
I followed the GooglePay implementation instructions here:
Now I'm trying to test out the functionality via Cypress for my website and I'm getting an error
ReferenceError: google is not defined at googlePayClient
I am using Vue 3 and creating my client that I'm trying to mock in the store like so:
googlePayClient(_, getters) {
return new google.payments.api.PaymentsClient({environment});
},
I am importing google in index.html like so:
<script async
src=".js"
></script>
I followed the GooglePay implementation instructions here: https://developers.google.com/pay/api/web/guides/tutorial
Now I'm trying to test out the functionality via Cypress for my website and I'm getting an error
ReferenceError: google is not defined at googlePayClient
I am using Vue 3 and creating my client that I'm trying to mock in the store like so:
googlePayClient(_, getters) {
return new google.payments.api.PaymentsClient({environment});
},
I am importing google in index.html like so:
<script async
src="https://pay.google.com/gp/p/js/pay.js"
></script>
Share
Improve this question
edited yesterday
Sarah
asked yesterday
SarahSarah
7032 gold badges9 silver badges24 bronze badges
2
|
1 Answer
Reset to default 2Mocks should be created in the test not the app, since you do not want to mock when a real user is accessing the app.
The <script>
to load the google
module places it as a global variable on the window object, so your test should do something like this:
cy.window().then((win) => { // "win" is the app window object
const google = win.google; // get the instance of google loaded via script
// now make your mock...
return new google.payments.api.PaymentsClient({environment})
本文标签: google payHow to mock GooglePay in CypressStack Overflow
版权声明:本文标题:google pay - How to mock GooglePay in Cypress - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736607463a1945363.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
google
. – Fernando Di Leo Commented yesterday