-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Unit Testing Chapter with Jasmine Examples #310
Comments
Would you as a reader prefer that the example be shown with a note stating that not every model should be tested and that this is simply a reference example or would you prefer for this example to be scrapped entirely. |
I would say remove it. At best, it's a intro to Jasmine and should be in a different book, in my opinion. At worst, it teaches developers to test code that's already been tested. I would suggest we teach readers to test the code they write. So, if you override a function - for instance, a model's Personally, I keep my models light, using Backbone's built in functionality, and so I don't usually test them as often as I do my views. I test my view's functions. I treat each function as a unit to be tested to ensure that the block of code I wrote behaves as expected. |
I agree with @AndrewHenderson, seems moot. |
I agree as well. |
I've found that it is easier to scope tests to my own code and not Backbone's if I don't instantiate the models/views. Instead I just test the methods directly on the prototype, often using fake contexts with spies. I did a small writeup of the method here. While it might need a high level of comfort with unit testing, Jasmine and spies, I still feel it makes testing Backbone object so much easier that it qualifies for being mentioned in the testing section. If you find any of it useful, @addyosmani , borrow away! |
Wasn't sure where to start a discussion thread on this, but I disagree with instructing developers to test whether a model returns the values passed to it. In my opinion, the code example below, taken from the current version of the book, is actually a test of the Backbone library's
get()
method.Even if you are testing that the engineer wrote the constructor
Todo()
correctly, should we be testing every model for such basic behavior? If so, where do you draw the line?You could make the same argument for testing every core functionality of a Backbone model. Why not check
save()
orclone()
for that matter;destroy()
,hasChanged()
. The list goes on.The text was updated successfully, but these errors were encountered: