问题标签 [rewire]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
reactjs - __RewireAPI__ as XXX 未能定义 XXX
我在 React 中使用rewire创建了一个简单的测试(在babel-plugin-rewire中为 React 实现),但无法让导入工作:
代码:
测试:
当我运行测试时,ClientSelectionMenuRewireAPI
是未定义的。我到底做错了什么?
jestjs - 如何在单元测试中将这些 rewire 语句转换为使用 jest.mock?
我已经看到使用类似这样的语法来模拟依赖项的单元测试:
但我也看到jest.mock
提到不少。我想知道,对于上述 Rewire 语句,jest.mock
等价物是什么?如果您有任何有用的文档也将不胜感激!(我很难找到有关 Rewire 的文档,因此很难理解这会是什么样子使用jest.mock
......)
node.js - How to force a return value from a mocked non-exported function using sinon or proxyquire or rewire?
I am just getting started unit testing nodejs. I have been using mocha, chai and sinon.
I hit a snag when I wanted to test a function which is not exported. proxyquire looks good, as does rewire.
There are lots of tutorials, but they tend to be simplistic. E.g
While that is nice, I want to be able to force the function saySecret
to return a specific value. The reason being that the function is called by a function which is exported, and I want to unit test the outer function, forcing it down failure paths.
How can I do that with sinon/proxyquire/rewire?