Created
June 20, 2012 15:39
-
-
Save DimitarChristoff/2960549 to your computer and use it in GitHub Desktop.
circular references and .spy cause RangeError: Maximum call stack size exceeded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: