单元测试 nuxt fetch hook
我正在尝试使用 Nuxt 进行单元测试。一切都很顺利,但我的问题在于单元测试获取。似乎由于 this.$axios 不是一个库(嗯,它是,但被注入到上下文中),所以没有简单的方法来 jest.mock 它。我有一些关于此的帖子,但它们没有起作用。
async fetch() {
try {
this.maxSpace = await this.$axios.$get('/api/system/max-space')
}
catch (err) {
this.maxSpace = 0
}
},
这是我尝试进行单元测试的简单代码
I'm trying to unit test with Nuxt. Everything's going smoothly, but my problem lies with unit testing fetch. It seems that since this.$axios isn't a library (well, it is, but is injected to the context), there's no easy way to jest.mock it. I've the few posts that there are on this, but they have not worked.
async fetch() {
try {
this.maxSpace = await this.$axios.$get('/api/system/max-space')
}
catch (err) {
this.maxSpace = 0
}
},
This is the simple code I'm attempting to unit test
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论