Skip to content

Instantly share code, notes, and snippets.

@DimitarChristoff
Created June 20, 2012 15:39
Show Gist options
  • Save DimitarChristoff/2960549 to your computer and use it in GitHub Desktop.
Save DimitarChristoff/2960549 to your computer and use it in GitHub Desktop.
circular references and .spy cause RangeError: Maximum call stack size exceeded
buster.testCase('breaking call stack when using circular references and spies', {
setUp: function() {
var A = function() {
this.collections = [];
}, B = function() {
this.models = [];
this.add = function(what) {
what.collections.push(this);
this.models.push(what)
};
};
this.model = new A();
this.collection = new B();
},
'Expect a model.collections to receive the collection it is a member of': function() {
var spy = this.spy();
this.collection.add(this.model);
Array.forEach(this.model.collections, spy);
buster.assert.calledWith(spy, this.collection);
}
});
@DimitarChristoff
Copy link
Author

I know this is an anti-pattern as such, got it from another MV* which tries to decorate models with all the collections that contain the model but they contain the model... anyway.

using this same code w/o a spy can pass any test you like, eg:

this.collection.add(this.model);
buster.assert.equals(this.collection, this.model.collections[0]);
  • which still means there may be something not right with the spy func.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment