jest matchers

发布时间 2023-06-08 21:58:10作者: 信尚
expect matcher more
boolean toBeTruthy() toBeFalsy()
object toStrictEqual() toEqual()
exception toThrow(error)
snap short toMatchInlineSnapshot() toMatchSnapshot()
  • object 优先使用toStrictEqual。因为undefined属性也会被检查。 e.g. {a: undefined, b: 2} will not equal {b: 2}

参照 https://jestjs.io/docs/expect#tostrictequalvalue

  • 快照优先使用toMatchInlineSnapshot。因为jest直接将快照的字符串参数添加到测试代码中,就不需要外部的快照文件了。