代码之家  ›  专栏  ›  技术社区  ›  Patrick Finnigan

相当于茉莉花。任何

  •  1
  • Patrick Finnigan  · 技术社区  · 8 年前

    我有一个断言失败:

    expect(obj1).to.deep.eq(expected);

    它失败,因为obj1具有更新的时间戳:

    "updatedAt": 1510356196161

    我想说 expected :

    {
        updatedAt: chai.any(number),
    }

    相当于茉莉花。任何柴有这样或类似的概念吗?

    2 回复  |  直到 8 年前
        1
  •  1
  •   artyhedgehog    8 年前

    不幸的是,该功能似乎尚未实现: https://github.com/chaijs/chai/issues/644#issuecomment-336197639

    到目前为止,我发现做这种断言的最好方法是逐道具:

    expect(obj1).to.have.property('updatedAt').that.is.a('number');
    expect(obj1).to.have.property('deletedAt').that.is.a('null');
    expect(obj1).to.have.property('name').that.equals('John Doe');
    
        2
  •  0
  •   Marcel    8 年前

    你试过以下方法吗?

    expect(obj1.updatedAt).to.be.a('number');