On my current project, I found the need for some pretty large data structures to test some of our growing Javascript code base. We’re using jasmine and jasmine-jquery. `jasmine-jquery` gives us the ability to easily pull in HTML fixture data on which we can run plugins etc. But there was no way to get JSON fixture data easily into the test framework. Instead of writing huge chunks at the top of the spec file that read
var test_data = [ ... blah blah blah ... ]; var more_complex_test_data = { ... blah blah ... };
I decided to add that functionality into jasmine-jquery. And my pull request was accepted in no time.
Now with jasmine-jquery, you can add to your jasmine specs (these are in CoffeeScript, but you get the idea) :
describe 'MyNewThing', -> beforeEach -> loadJsonFixtures('fixture1.json','fixture2.json') fixture1 = getJsonFixture('fixture1.json') @testable = new MyNewThing(fixture1) it 'does the right thing with data' -> expect(@testable).to ...
Thanks to Travis Jeffery for merging in the pull request.
Keep testing!
Advertisements
Good job – exactly what I was looking for this morning.