Also, I think I was wrong (again) in one of my blog posts. It seems like calling
mock.verify()
on a mock doesn't actually clear expectations, so if you have multiple expectations dealing with the same mocked method, you will run into problems. So I think that doingbeforeEach(function () { mock = sinon.mock(obj); });is necessary when expecting multiple calls to the same method across different tests.
I also realized that the BOOK_OBJECT constant we use in our tests (for example) wouldn't reflect any new changes we made to how
Book
objects are generated from librivox json (for example, changing the id from a string to an integer had to be manually done in BOOK_OBJECT alongside app.js). I fixed this somewhat by setting book object to var BOOK_OBJECT = new Book({json: WEB_RESP.book_json});
so that our test book object will be generated from our json each time the tests are run. I'm still a bit fuzzy on this aspect of testing, so this might not be best practice. I'll check with Kevin.
I worked on cleaning up our tests. I moved the tests for each object into separate files. I also moved all the simulated web response objects into their own object so that the global namespace didn't get start getting polluted (even though it was only three things, I like it better this way). So now the responses can be gotten with
WEB_RESP.audio_blob
WEB_RESP.book_json
WEB_RESP.book_xml
.
No comments:
Post a Comment