- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 JEST 匹配器 toMatchObject
来确保对象包含多个属性并且一些值是静态的,而其他一些值应该匹配特定的正则表达式
问题是:当静态值不匹配时,输出也会显示正则表达式值不匹配,尽管它们很好
代码:
test("asdf", async () => {
const actual = {
a: "a_value",
b: "b_value",
c: "c_value"
}
expect(actual).toMatchObject({
a: expect.stringMatching("[a-z]_value"),
b: "b_value",
})
expect(actual).toMatchObject({
a: expect.stringMatching("[a-z]_value"),
b: "B_VALUE",
})
})
输出:
Expected value to match object:
{"a": StringMatching /[a-z]_value/, "b": "B_VALUE"}
Received:
{"a": "a_value", "b": "b_value", "c": "c_value"}
Difference:
- Expected
+ Received
Object {
- "a": StringMatching /[a-z]_value/,
- "b": "B_VALUE",
+ "a": "a_value",
+ "b": "b_value",
}
我只想在此处的输出中看到不匹配的值,因为正则表达式没问题:
Object {
- "b": "B_VALUE",
+ "b": "b_value",
最佳答案
这似乎是 Jest 错误,https://github.com/facebook/jest/issues/6928 .
关于typescript - 在 Jest 中使用 toMatchObject 和 stringMatching(regexp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52092233/
我对我的 Mongoose 模型进行了测试,虽然一个模型的测试运行完全正常,但另一个模型基本上是一个副本 - 不起作用。老实说我不明白这个问题。我尝试删除一些属性或添加硬编码值以真正 100% 完全匹
我对我的 Mongoose 模型进行了测试,虽然一个模型的测试运行完全正常,但另一个模型基本上是一个副本 - 不起作用。老实说我不明白这个问题。我尝试删除一些属性或添加硬编码值以真正 100% 完全匹
我正在使用 Jest 来测试我的 Node 应用程序,以下情况验证了一些数据已添加到数据库中(考虑 DB 逻辑工作正常): it("should add empty string hooks if n
我正在测试一个对象是否匹配一组字段,但其中一个是 float ,我需要使用 .toBeCloseTo .如何在一个 expect 内完成? expect(foo).toMatchObject({
我写了下面的测试: it('Can decrement the current step', function () { expect(reducer(TestState, { type: '
假设某个东西返回一个复杂的对象: const value = { ..., client: { ... }, ... }; 我想测试一堆属性,对于client我想确保它有一定的
我想用 jest 测试返回的对象是否符合我的预期。 我正在尝试这个: const desiredResult = { host: '192.168.1.1', port: expect.any
我正在使用 JEST 匹配器 toMatchObject 来确保对象包含多个属性并且一些值是静态的,而其他一些值应该匹配特定的正则表达式 问题是:当静态值不匹配时,输出也会显示正则表达式值不匹配,尽管
我有一个快速 API 端点,它返回一个对象,并且在该对象上有一个属性(在我们下面的示例中为 property3),它的值是日期。 例如 res.body = { "property1
我正在测试一个 React 应用程序,它基本上遵循了标准的、官方认可的 create-react-app 设置。 我的测试如下: import React from 'react'; import {
我是一名优秀的程序员,十分优秀!