腾讯云
开发者社区
文档
建议反馈
控制台
首页
学习
活动
专区
工具
TVP
最新优惠活动
文章/答案/技术大牛
搜索
搜索
关闭
发布
登录/注册
精选内容/技术社群/优惠产品,
尽在小程序
立即前往
文章
问答
(9999+)
视频
沙龙
1
回答
Jest
mockImplementationOnce
没有
覆盖
手动
模拟
typescript
、
mocking
、
jestjs
我在__mocks__文件夹中有一个名为client.ts的
手动
模拟
。现在在我的单元测试中,我调用了
jest
.mock('./client')。这可以很好地工作,并且
jest
会导入mocked文件夹。现在我有一个场景(测试),我需要
覆盖
这个行为。我在单元测试中使用了
mockImplementationOnce
。/client'; (mockClient.getObject as
jest
.Mock).
mockIm
浏览 34
提问于2019-09-27
得票数 3
1
回答
如何用
jest
模拟
node_module内部的构造函数?
javascript
、
node.js
、
unit-testing
、
jestjs
、
cote
Jest
可以选择
模拟
node_module我试图模仿的模块是cote模块。是来自模块的index.js文件。const player = await requester.send({type:'findOnePlayer',username:username, password: password}) 如何使用
jest
设置Requester的构造函数,使来自
模拟
cote模块的构造器返回
模拟
对象,该
浏览 1
提问于2018-09-19
得票数 2
回答已采纳
2
回答
使用
Jest
(React)对navigator.permissions.query({ name:'geolocation‘})进行单元测试
reactjs
、
unit-testing
、
jestjs
、
enzyme
我试着
模拟
这个函数 const location = window.navigator && window.navigator.geolocation; location.getCurrentPosition} }); 到目前为止,我尝试的是在setupTest.js创建全局导航器 const mockGeolocation = { .
mockImplementationOnce
((success)
浏览 81
提问于2020-06-11
得票数 1
2
回答
Jest
模拟
模块使用变量值解析
reactjs
、
testing
、
promise
、
jestjs
我想
模拟
这个承诺的不同结果来测试这个模块所包含的功能。我像这样
模拟
这个模块:
jest
.mock('..我试图在测试中调用
jest
.doMock,但这不能正确地触发请求。 我试着去做 const mockResponse =
jest
.fn();
jest
.mock("..目前还
没有
成功。有谁能找到出路吗?
浏览 23
提问于2019-01-28
得票数 0
回答已采纳
1
回答
即使在命中行时,代码
覆盖
率也会丢失。
javascript
、
reactjs
、
react-hooks
、
jestjs
、
enzyme
甚至通过
模拟
测试功能,测试也很好。请告诉我如何用代码来掩盖这个问题。谢谢。正在测试的
浏览 5
提问于2022-02-28
得票数 2
2
回答
Jest
:如何使用构造函数
手动
模拟
模块(ioredis)
jestjs
我正在遵循
Jest
中的
手动
模拟
示例// __mocks__/ioredis.js'use strict'; const IOR
浏览 13
提问于2017-05-22
得票数 2
1
回答
Jest
模拟
模块以在函数调用上产生不同的结果
javascript
、
unit-testing
、
jestjs
、
mocking
这是我的
模拟
机制:问题是
mockImplementationOnce
不是
jest
.mock()的函数。这只是
jest
.fn()的一个函数。
jest
.mock()对象只有mockImplementation,它将
模拟
和密封
模拟
函数的返回结果,并且不允许在多次调用时出
浏览 1
提问于2021-07-13
得票数 0
2
回答
TypeScript的
Jest
模拟
javascript
、
reactjs
、
typescript
、
jestjs
index', () => { const root = <div />; ...ReactDOM.render.mockRestore();} ); 我得到以下typescript错误:"TS2
浏览 3
提问于2018-06-18
得票数 6
1
回答
仅为一个测试用一个新的
模拟
重写现有/共享
Jest
模拟
javascript
、
testing
、
jestjs
、
integration-testing
我有一个使用套件的
Jest
集成测试套件--用于数据库访问的全局
模拟
,根据这些测试套件,我返回不同的
模拟
响应:it('should throw and handle an error if the db returns no results for据我所知,这是mockClear()、
浏览 1
提问于2021-06-04
得票数 1
1
回答
类方法
没有
在
Jest
中进行
模拟
。
node.js
、
unit-testing
、
google-cloud-firestore
、
jestjs
('@google-cloud/firestore', () =>
jest
.fn(() => ({ .mockReturnThis().mockResolvedValue({ docs: [] }), set:
jest
.fn().mockReturnThis(), limit:
jest
.
浏览 4
提问于2022-02-11
得票数 0
回答已采纳
1
回答
如何
模拟
节点的readline?
javascript
、
node.js
、
typescript
、
jestjs
if (answer.toLowerCase() === "y") { } });describe.only("program",
浏览 14
提问于2019-01-06
得票数 5
回答已采纳
1
回答
如何
模拟
useSWRConfig实现?
reactjs
、
jestjs
、
mocking
、
swr
有
没有
一种方法来
模拟
useSWRConfig钩子在
Jest
测试中的实现?import useSWR, { useSWRConfig } from 'swr'; const mutation =
jest
.fn(); useSW
浏览 6
提问于2021-12-21
得票数 1
3
回答
如何在React组件中
模拟
服务以在
jest
中隔离单元测试?
javascript
、
reactjs
、
unit-testing
、
jestjs
axios来测试ObjectList是否如我所期望的那样呈现数据:
jest
.mock('axios') data: require('.ObjectList', () => { axios.get.
mockImplementationOnce
><
浏览 5
提问于2020-08-06
得票数 1
回答已采纳
3
回答
取笑如何
模拟
类型记录类,但只在一个测试中替换某些方法行为,而在其他测试中不修改
模拟
。
javascript
、
typescript
、
unit-testing
、
jestjs
、
ts-jest
userInfo.ts: public getName() { }我在文件夹中有一个
模拟
类let validation = new UserInfo(); } 最后,我希望有两个测试,在第一个测试中,我只想为这个测试
覆盖
getName
模拟
,在第二个测试中,我希望有
模拟
的类行为,所以: import { Clie
浏览 6
提问于2021-12-28
得票数 0
回答已采纳
1
回答
如何用
Jest
伪装链式MongoDB函数
javascript
、
mongodb
、
unit-testing
、
jestjs
、
mocking
我试图
模拟
MongoClient的insertMany函数。有了这个
模拟
,我将不再使用真正的mongo,而是使用带有
Jest
的
模拟
实现。DbConnection.db(.).collection不是函数
模拟
const DbConnection = { db: () =>
jest
.fn().
mockImplement
浏览 2
提问于2021-08-18
得票数 0
回答已采纳
1
回答
Jest
spyOn仅在第二次调用和第三次调用时
模拟
实现
javascript
、
node.js
、
mocking
、
jestjs
我有一个函数,我只想在第二次调用和第三次调用时
模拟
它,但在第一次调用时使用默认实现。我看过
Jest
文档,有一个函数
mockImplementationOnce
可以用来
模拟
单个调用的实现。有
没有
一个我可以使用的函数,让它对第一次调用使用默认实现,而只
模拟
第二次和第三次调用?functionCalls = 0; fetchValues() { fetchValues();};
jest
浏览 31
提问于2020-04-27
得票数 6
2
回答
Jest
+
MockImplementationOnce
+第二次不工作了
node.js
、
unit-testing
、
jestjs
我正在为我的node.js项目使用
JEST
框架进行单元测试。我使用
mockImplementationOnce
来
模拟
thirdParty库方法如下:
jest
.mock('abc',() => {abc{ a:{ b:
jest
.fn() };});constrequire('abc'); test("should return true", asyn
浏览 13
提问于2020-11-24
得票数 9
1
回答
TypeError:无法指定对象“#<Performance>”的只读属性“now”
node.js
、
npm
我刚刚将节点升级到最新版本v16.13.1,我试图运行一个现有的项目,但由于以下错误,它崩溃了: ^ at Function.present.conflict (/Project_Path/node_modules/mstime/dist/cjs/present.js:39:19) at Ob
浏览 3
提问于2021-12-24
得票数 2
3
回答
如何使用
Jest
模拟
和自定义从npm包导入的函数值?
reactjs
、
unit-testing
、
mocking
、
jestjs
我想在我的
jest
单元测试中定制isMobileOnly的返回值。但它似乎对我不起作用。我也尝试过:
jest
的mockImplementation
jest
的
mockImplementationOnce
jest
的spyOn在我的
jest
单元测试中,我想以这样一种方式
模拟
浏览 2
提问于2019-06-17
得票数 0
2
回答
无法在
Jest
中
模拟
jwt-解码
typescript
、
testing
、
mocking
、
ts-jest
为了测试目的,我需要
模拟
jwt函数,但是我在这里发现的任何建议都
没有
帮助。const { exp } = jwtDecode(accessToken);
jest
.mock('jwt-decode', () => () => ({ exp: 123456 })); const { exp } = jwtDecode('123456
浏览 13
提问于2022-01-31
得票数 0
点击加载更多
扫码
添加站长 进交流群
领取专属
10元无门槛券
手把手带您无忧上云
相关
资讯
React 16 Jest手动模拟
前端单元测试入门
携程租车React Native单元测试实践
流利说前端单元测试实践
使用Jest测试原生TypeScript项目
热门
标签
更多标签
活动推荐
运营活动
广告
关闭
领券