【发布时间】:2017-10-06 20:52:47
【问题描述】:
这是我的代码:
const Config = require('Config');
export const getPayments = (username: string) => {
if (username === undefined) {
throw new Error('username is undefined');
}
const envEndpoint = Config.paymentsEndpoint;
const endpoint: string = `${envEndpoint}/${username}`;
return fetch(endpoint);
};
我要模拟的是 Config 对象。我基本上想在我的测试文件中拦截那个 require 调用,并将其替换为具有该 paymentEndpoint 值的对象。我正在使用 jest,但也有 sinon 作为模拟的选项。
我对单元测试和玩笑还是很陌生,所以如果我使用了不正确的术语,请原谅我
【问题讨论】:
标签: unit-testing sinon jestjs