gpt4 book ai didi

javascript - 在 Jest 测试中模拟 auth0-spa-js 的安全来源

转载 作者:行者123 更新时间:2023-12-03 12:16:07 28 4
gpt4 key购买 nike

尝试围绕 auth0-spa-js 设置 Jest 测试,但在尝试等待 createAuth0Client(config) 时收到错误“auth0-spa-js 必须在安全源上运行”。在 Jest 测试中模拟安全来源的最佳方法是什么?

最佳答案

在深入研究 auth0 代码以查看它想要什么之后,我给了它 global.crypto.subtle = {} 并且它似乎已经满足了它,错误消失了,测试通过了:

const JSDOM = require('jsdom').JSDOM

Object.defineProperty(global.self, 'crypto', {
value: {
getRandomValues: arr => crypto.randomBytes(arr.length)
}
})
global.crypto.subtle = {} // this gets around the 'auth0-spa-js must run on a secure origin' error

关于javascript - 在 Jest 测试中模拟 auth0-spa-js 的安全来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60370138/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com