期望数组包含打字稿中类型的对象(Jest)
我想用 Jest 在打字稿中编写一个单元测试,检查返回的数组是否包含具有指定类型的一个元素。我知道以下方法:
expect(array).toBeInstanceOf(myType)
:这不起作用,因为它仅适用于单个元素,并且我想检查数组中的一个元素是否具有该方法typeexpect(array).toContain(myType)
:这不起作用,因为它检查我传入的对象是否相等(我只关心类型)
无论如何我可以将两者结合起来?或者进行此检查的最佳方法是什么?
谢谢,
I would like to code a unit test in typescript with Jest, that checks whether a returned array contains one element with a specified type. I am aware of the following methods:
expect(array).toBeInstanceOf(myType)
: this does not work, since it only works for single elements and I want to check whether one element in the array has that typeexpect(array).toContain(myType)
: this does not work, since it checks for equality of the object I am passing in (I only care about the type)
Is there anyway in which I could combine the two? Or what would be the best way of doing this check?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论