LoginSignup
3
3

More than 5 years have passed since last update.

node.js/mochaでObjectをassertする

Posted at

shouldを使ってテストしていたんですがshouldだとObjectが
比較出来ないようでハマりました。

actual = { foo:"foo", bar:"bar" };
expect = { foo:"foo", bar:"bar" };
actual.should.equal(expect);

どう見てもパスしそうですがAssertion Errorになります。
とりあえず、shouldでやることをやめて、assertを使うことに

actual = { foo:"foo", bar:"bar" };
expect = { foo:"foo", bar:"bar" };
assert.equal(actual, expect);

これもだめでした。以下のようにするようです。

actual = { foo:"foo", bar:"bar" };
expect = { foo:"foo", bar:"bar" };
assert.deepEqual(actual, expect);

これでやりたいことできました。
Object同士の比較は難しいですね。

3
3
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
3
3