i have rest client written part of angularjs application want write tests for; tried jasmine (using passthrough on $httpbackend) not talk real endpoint @ (which requirement).
does know of sensible library allows this? or alternatively, way of wrestling jasmine submission?
you need inject first $httpbackend
describe('mycontroller', function() { var $httpbackend, $rootscope, createcontroller, authrequesthandler; // set module beforeeach(module('myapp')); beforeeach(inject(function($injector) { // set mock http service responses $httpbackend = $injector.get('$httpbackend'); // backend definition common tests authrequesthandler = $httpbackend.when('get', '/auth.py') .respond({userid: 'userx'}, {'a-token': 'xxx'}); // hold of scope (i.e. root scope) $rootscope = $injector.get('$rootscope'); // $controller service used create instances of controllers var $controller = $injector.get('$controller'); createcontroller = function() { return $controller('mycontroller', {'$scope' : $rootscope }); }; $httpbackend.when('get', "/api/rest/").respond(data_to_respond); }));
next write test cases
it('gettypes - should return 3 car manufacturers', function () { service.gettypes().then(function(response) { //expect here }); $httpbackend.flush(); });
Comments
Post a Comment