lundi 29 février 2016

load DRY test data object without use $httpBackend for angularjs unit test in jasmine

my unit test is for a directive's controller which does not rely on any external http calls. My several attempts on using the $httpBackend has failed ( read more than 10 articles about that $httpBackend)...

I wonder, if there is way to inject data synchronously into the my-test.spec.js file? the data not really need to be a json per say, since json needs to be converted into js objects anyway.

So far I tried to add 'spec/mock-data.js' (contains a global var mockData ={abc:"123"}), into karma.conf.js but seems my describe block's forEach section does not really see that global var and returns undefined

I wonder am I missing something here? if not, then is there a better way for me to injecting ready-to-use data rather than json, that so I can reusable throughout different spec files as if I would have loaded with $httpBackend?

I tried the way described here, but that's when I got undefined instead.

Aucun commentaire:

Enregistrer un commentaire