help please write a test for backbone / jasmine

there is a model:

window.APP = window.APP || {}; APP.CalcModel = Backbone.Model.extend({ defaults: { errDepartCity: [], errDestinCity: [], errShippOptionsWeight: [], errShippOptionsVolume: [] } }); 

In this model there is a method that clears the properties. For now, to simplify the task, I would like to initialize the model with data and check empty fields or not. here is my test:

 describe("fill model check", function() { it("should errDepartCity is not empty after init", function() { var model = new APP.CalcModel({ errDepartCity: ['qwerty', 'asdfgh'], errDestinCity: ['qwerty', 'asdfgh'], errShippOptionsWeight: ['qwerty', 'asdfgh'], errShippOptionsVolume: ['qwerty', 'asdfgh'] }); // console.log(model); expect(model.get('errDepartCity').length).toEqual(0); }); }); 

the problem is that it passes successfully. although it should not because the length of the array is not zero. I do not understand why

using not.toEqual instead of .toEqual changes nothing - the test passes successfully

  • one
    Are there any other tests where you create an APP.CalcModel ? If yes, then the problem is really in reference types in defaults as @AriesUa says - Dmitriy Simushev
  • By the way, apart from jasmine, everything works as it should: jsfiddle.net/yyq0y1z9 - Dmitriy Simushev
  • I am sorry, misled. - Aries Ua
  • one
    But the problem of passing by reference exists. Here is a small example that shows this. jsfiddle.net/zhf8zzu6/1 - Aries Ua
  • one
    @AriesUa, which is why I clarified the existence of other tests. =) - Dmitriy Simushev

0