angularjs - Mocking multiple return values for a function that returns a success/error style promise? -


nb: code reproduced memory.

i have method generated djangoangular has signature in service:

angular.module('mymodule') .service('pythondataservice',['djangormi',function(djangormi){      return {getdata:getdata};       function getdata(foo,bar,callback){          var in_data = {'baz':foo,'bing':bar};          djangormi.getpythondata(in_data)          .success(function(out_data) {             if(out_data['var1']){                  callback(out_data['var1']);              }else if(out_data['var2']){                  callback(out_data['var2']);             }          }).error(function(e){             console.log(e)          });         }; }]) 

i want test service in jasmine, , have mock djangoangular method. want call through , have return multiple datum.

this (sort of) have tried far, reproduced memory:

describe('python data service',function(){     var mockdjangormi,     beforeeach(module('ng.django.rmi'));     beforeeach(function() {         mockdjangormi = {             getpythondata:jasmine.createspy('getpythondata').and.returnvalue({                 success:function(fn){fn(mockdata);return this.error},                 error:function(fn){fn();return}             })         }         module(function($provide) {             $provide.provide('djangormi', mockdjangormi);        });    });    it('should data',function(){        mockdata = {'var1':'hello stackexchange'};        var callback = jasmine.createspy();        pythondataservice.getdata(1,2,callback);        expect(callback).tohavebeencalled();    }) }) 

but when put it block in different value mockdata, 1 of them picked up.

i'm guessing because of order of operation not right how i'm assigning mockdata. how can mock multiple datum djangormi function?


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

node.js - Express and Redis - If session exists for this user, don't allow access -