I'm writing tests using Teaspoon and Jasmine for my Rails app. I understand, for the most part, how to test standalone js modules but I'm not sure how to go about testing a module that binds to a DOM ready event like with JQuery's $(document).ready()
.
Ideally I could set up a fixture before requiring the JS file, but if I don't put the require
as the first statement, then it is ignored.
How does one usually go about testing this?
I would've wanted to do something like:
cool.js:
$(document).ready(function() {
$(".stuff").click(stuffClickHandler);
}
cool_spec.js:
fixture.load("fixture_with_stuffs.html");
//= require cool
describe("on ready", function() {
it("should bind handlers to all stuffs", function() {
// test stuffs for handlers
});
});
But that doesn't work, because if the //= require
comes after anything, it doesn't seem to load the js.
Aucun commentaire:
Enregistrer un commentaire