【发布时间】:2018-08-30 08:42:36
【问题描述】:
我想测试一个数组是空的还是包含某种结构的对象。在伪代码中可能是这样的:
expect([])
.toHaveLength(0)
.or
.arrayContaining(
expect.toMatchObject(
{ foo: expect.any(String) }
)
) => true
expect([{foo: 'bar'}])
.toHaveLength(0)
.or
.arrayContaining(
expect.toMatchObject(
{ foo: expect.any(String) }
)
) => true
expect([1])
.toHaveLength(0)
.or
.arrayContaining(
expect.toMatchObject(
{ foo: expect.any(String) }
)
) => false
也许我对 Jest 中的工作方式有误,但对我来说,我的问题看起来像是一个或问题。
【问题讨论】:
标签: javascript testing jestjs