LoginSignup
0
0

More than 5 years have passed since last update.

jestのexpect.anything()が効かなかった

Posted at

jestでオブジェクトが同値でであることをテストする際、テスト対象のオブジェクトにnew Date()とかの値が含まれている場合、new Date()の値がいくつになるのかは当然わからないのでexpect.anything()を使うといいよ、という記事を見つけた。参考

でもこんな感じになってテストが通らない。
スクリーンショット 2019-03-07 10.15.59.png

こうなってたのを

      expect(user).toEqual({

こうしたらテストが通った

      const userJSON = JSON.parse(JSON.stringify(user));

      expect(userJSON).toEqual({
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0