我使用的是Jest 20.0.3,测试很简单:
it('should return a Promise', () => {
expect(new Promise(r => r())).toBeInstanceOf(Promise);
});
并且
失败● should return a Promise
expect(value).toBeInstanceOf(constructor)
Expected value to be an instance of:
"Promise"
Received:
{"fulfillmentValue": undefined, "isFulfilled": false, "isRejected": false, "rejectionReason": undefined}
Constructor:
"Promise"
同时,如果我测试Object的实例,它可以工作:
it('should return an Object', () => {
expect(new Object()).toBeInstanceOf(Object); // <- this one passes
});
我尝试将实例的构造函数与Promise对象进行比较,但它仍然无法正常工作。我尝试使用expect(•).toHaveProperty
并检查返回的对象是否有&#34;然后&#34;并且&#34;赶上&#34;属性,但似乎不是,所以测试也失败了。
我做错了什么?如何测试函数的返回值必须是Promise实例?