【发布时间】:2020-09-30 13:50:35
【问题描述】:
我正在尝试从外部库中存根导入的方法。我可以让这个存根方法与内部库一起使用,我在外部库中哪里出错了?
例子:
索引.tsimport {format} from "date-fns";
export class Index {
public now(): string {
return format(new Date(), "Pp");
}
}
索引.test.ts
import {expect} from 'chai';
import * as sinon from "sinon";
import 'mocha';
import {Index} from './index';
describe("index unit tests", async function () {
let dfns = await import("date-fns");
it("get should return mock", async function () {
sinon.stub(dfns, "format").returns("x");
expect(new Index().now()).to.equal("x");
});
});
【问题讨论】:
标签: typescript sinon