如何从接口模拟对象?

时间:2019-06-05 11:55:01

标签: typescript unit-testing mocking jestjs

给定打字稿中的接口,我可以自动从其中模拟出一个带有伪值的新对象,而不是手动编写对象吗?

让我们以下面的interface为例:

interface SquareConfig {
    color: string;
    width: number;
}

我想有一个实现接口属性的模拟对象,例如:

const mockConfig = jest.mock<SquareConfig>();
console.log(mockConfig.color); //should print some auto-generated dummy string value

有可能吗?

0 个答案:

没有答案
相关问题