angularjs - How to test an Angular Factory which uses Parse SDK -
This is my first question here. I will try my best I have searched a lot before posting I am developing an angular JS application that is dependent on Javascript. I have assured myself to dive into the test recently, so I am making a start. I have this factory It comes like this: My question: UserFactory.current () How does it use an external service? I'm jokingly pars SDK, but it does not know how to do this because it is not related to any type (i.e.: httpBackend can not be used). My current test file: Thank you from
myModule.factory ('UserFactory', ['$ q', function ($ q) {var user = pars.USAR .inded ({// instance}}, {// static / class methods // overrides parse. User.} {Var deferred = $ q.defer (); var current user = pars.USIR. (); if (current User) suspended.Rolove (current user); and deferred.Disclaimed ("no current user"); delay is returned.;}}); Return user;}]);
("Unit: UserFinder", function () (every user factor) first (function () (module ("myModule"); Injection (_UserFactory _) {UserFactory = _UserFactory_;}}}}}; user ", function () {// what is expected?});});
description ("unit: userfitter", function () (first user) ( Every first) (function () (module ("myModule"); injection (function (_UserFactory _) {UserFactory = _UserFactory_; $ rootScope = _ $ r OotScope_;});}); description ('on'), function () {var success callback, error callback; first (function () {successCallback = jasmine.createSpy ('success'); errorCallback = jasmine.createSpy (' Error ');}); ("Promise should be done if Parse.User.current is true", function () {spyOn (pars user,' on ') .and Thornewell (true); UserFactory.current () Then (success callback, error callback); $ rootsecope. $ Digest (); hopefully (success callback.Count. Coat) (). ToBe (1); Expect (ErrorColakbackCollsCot) ()). ToBe (0); Hope (pars. ;}); ("Promise should be rejected if Parse.User.current is falsy", function () {spyOn (Parse.User, 'current') and turnValue (false); UserFactory.current (). Then (succe Ss callback , ErrorColokback); $ RootScope $ digest (.) Hopefully (errorCallback.calls.count ()) Tobey (1). Hopefully (successCallback.calls.count ()) Tobey (0). Hopefully (Parse.User.current). ToHaveCalledOnce ();}); }); });
Comments
Post a Comment