Jasmine抱怨一个物体不等于一个物体

时间:2015-01-20 16:58:19

标签: meteor jasmine meteor-velocity meteor-jasmine

我正在尝试使用jasmine进行一些集成测试。我正在做以下事情:

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]);
    });
  });
});

但是当这种情况发生时,Jasmine抱怨如下:

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 } ]

因此,从错误消息中,它说A不等于A.我如何修改测试以使其工作?

1 个答案:

答案 0 :(得分:1)

您需要使用toEqual代替toBetoEqual将进行深入比较:如果所有属性相等,则认为两个对象都相等。