I am trying to write a unit test for the Angarius Association with the subject and Jasmine using the PhantomJes browser is. The service that I want to test uses nested promises (to read an indexed database, to get an answer from the server and to write the response back into the database).
This should be done while writing in the database (write local db, put post / server, update local db with server id) Testing except for tests to handle the connection loss to the server I am writing all the work.
When this happens, then the sync () method sets the online status incorrectly and creates $ timeout which repeatedly checks for a connection by making a recursive call if the connection comes again , All unaccented data will be synchronized (and the promise of the corresponding sync () call will be resolved).
Description ('Hermaged', function () {var ... // setting all 'global' variable [...] Function () {// know that the service sends a ping so that it can check that online again pingGet = backend ('GET', 'http: // localhost: 2403'); pinggate. (0); testTablePut121 = Backend.when ('PUT', 'http: // localhost: 2403 / test_table / 121'); testTablePut121. (Function (method, url, data, header) {...} // 200 [...]} [...] Returns (should try to sync the saved element, but because of missing server's Which should fail from connectivity ', function () {var list; var timeoutCounter = 0; _checkOnline = harmonized._checkOnline; // harmonized is a service that should be tested. _checkOnline = function () {// only the original function Call twice if (timeout counter ++ & lt; 2) {_checkOnline (); // $ timeout and $ httpBackend timeout. Flush (2000) flush; backend.flush (1); // Progress causes error due to digest in console.log ('after tick'); }}; All.getList () Then (function (entries) {list = entries; testTablePut121. (0); pingGet = backend.expect ('GET', 'http: // localhost: 2403'); pingGet.sund (0), but detective (list [ 0], 'sync') and. CallThrough (); [0]. Saving (). Then (// resolution called when the server call was successful (task) (expect) [synchronize [0]. .toBeTruthy (); Hopefully (List [0] .sync.calls.count ()). ToBe (2); console.log ('done');}, // is rejected when any other than server 0 Other error (which is not the case in this test space) feedback, // indicate that B is the local DB save function () (Hopefully (list [0] .sync.calls.count ()) .toBe (1); Hopefully (list [0] ._ synchronize) .toBeFalsy ();}); Backend.flush (1);}); Backend.flush (1); });
When the backend.flush () function is asked to flush the HTTP request made in the second time (save) function, I get an error that the $ digest before Except for the line, do not flush the request (and this also causes an error).
Is there any way to flush everything at the right time without getting $ digest error?
No comments:
Post a Comment