Wait for the promise to be fulfilled before running the next test

In Jasmine 2.5 the "it" function takes an optional parameter that should
be called when the async work is completed (returning a promise was
introduced in Jasmine 2.7, so it is not supported yet in the tests). If
the parameter is not declared then the next test is executed without
waiting for the asynchronous work in the previous one to finish, which
could cause that asynchronous work to finish while a different test is
being run.

Note that if that happens the test could still work as expected if it
relied only in local variables. However, in the case of the successful
revert tests, the stubs being checked are not the ones created when that
test was initialized, but the ones created when the next test, the
failed revert test, was initialized and the previous variables were
replaced (although the model itself calls the proper stubs, as they are
set through parameters in function calls).

Besides all that, the checks in the failed revert test were never
executed due to a different problem which will be fixed in the next
commit.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2018-10-25 12:25:41 +02:00
parent 58fde16226
commit 24abfd8869
1 changed files with 6 additions and 4 deletions

View File

@ -58,7 +58,7 @@ describe('OCA.Versions.VersionModel', function() {
model.on('revert', revertEventStub);
model.on('error', errorStub);
});
it('tells the server to revert when calling the revert method', function() {
it('tells the server to revert when calling the revert method', function(done) {
var promise = model.revert({
success: successStub
});
@ -76,11 +76,11 @@ describe('OCA.Versions.VersionModel', function() {
expect(revertEventStub.calledOnce).toEqual(true);
expect(successStub.calledOnce).toEqual(true);
expect(errorStub.notCalled).toEqual(true);
});
return promise;
done();
});
});
it('triggers error event when server returns a failure', function() {
it('triggers error event when server returns a failure', function(done) {
var promise = model.revert({
success: successStub
});
@ -92,6 +92,8 @@ describe('OCA.Versions.VersionModel', function() {
expect(revertEventStub.notCalled).toEqual(true);
expect(successStub.notCalled).toEqual(true);
expect(errorStub.calledOnce).toEqual(true);
done();
});
});
});