meteorjasminemeteor-velocitymeteor-jasmine

Jasmine is complaining that an object is not equal to an object


I am trying to do some integration testing using jasmine. I am doing the following:

Jasmine.onTest(function () {
  describe("Form", function() {
    it("should lazy-load HeaderFields and FormFields", function() {
      var hf1 = new HeaderField({
        label: "Test HF1",
        required: false,
        sequence: 1,
        field_type: "TEXT",
        allows_pictures: false,
        record_geo: false,
        form_report_searchable: false
      });
      hf1.save();

      var ff1 = new FormField({
        label: "Test FF1",
        required: false,
        sequence: 1,
        field_type: "TEXT",
        allows_pictures: false,
        allows_comments: false,
        record_geo: false
      });
      ff1.save();

      var form = new Form({
        title: "Test Title",
        header_fields: [hf1.id],
        form_fields: [ff1.id],
        created_by: "4444444",
        created_on: new Date()
      });
      form.save();

      // _headerFields and _formFields should both be undefined right now
      expect(form._headerFields).toBe(undefined);
      expect(form._formFields).toBe(undefined);

      // Now trigger the lazy-loading of both, now they should not be null
      var headers = form.headerFields;
      var fields = form.formFields;
      expect(form._headerFields).toBe([{_id: hf1.id, _label: 'Test HF1', _form_id: null, _sequence: 1, _field_type: 'TEXT', _field_options: null, _field_value: null, _required: false, _allows_pictures: false, _record_geo: false, _form_report_searchable: false}]);
      expect(form._formFields).toBe([ff1]);
    });
  });
});

But when this runs, Jasmine complains with the following:

Expected [ { _id: '8WwdEfxfm7Df3Z8EH', _label: 'Test HF1', _form_id: null, _sequence: 1, _field_type: 'TEXT', _field_options: null, _field_value: null, _required: false, _allows_pictures: false, _record_geo: false, _form_report_searchable: false } ] to be [ { _id: '8WwdEfxfm7Df3Z8EH', _label: 'Test HF1', _form_id: null, _sequence: 1, _field_type: 'TEXT', _field_options: null, _field_value: null, _required: false, _allows_pictures: false, _record_geo: false, _form_report_searchable: false } ]

So, from the error message, it's saying A is not equal to A. How can I modify the test to make this work?


Solution

  • You need to use toEqual instead of toBe. toEqual will do a deep comparison : if all the properties are equal, both objects are considered equal.