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 which wrap around the SDK so that everything is angled in a clean and modular way. That is: SDK is used only through factories (not controlling or directive).

It comes like this:

  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;}]);   

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:

  ("Unit: UserFinder", function () (every user factor) first (function () (module ("myModule"); Injection (_UserFactory _) {UserFactory = _UserFactory_;}}}}}; user ", function () {// what is expected?});});   

Thank you from

  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

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -