Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions apps/files_versions/tests/js/versionmodelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -76,22 +76,32 @@ 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
});

expect(fakeServer.requests.length).toEqual(1);
fakeServer.requests[0].respond(404);
var responseErrorHeaders = {
"Content-Type": "application/xml"
};
var responseErrorBody =
'<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">' +
' <s:exception>Sabre\\DAV\\Exception\\SomeException</s:exception>' +
' <s:message>Some error message</s:message>' +
'</d:error>';
fakeServer.requests[0].respond(404, responseErrorHeaders, responseErrorBody);

promise.then(function() {
promise.fail(function() {
expect(revertEventStub.notCalled).toEqual(true);
expect(successStub.notCalled).toEqual(true);
expect(errorStub.calledOnce).toEqual(true);

done();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the "non-fail" case? Shouldn't there also be a done()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not needed; if done() is not called in jasmine.DEFAULT_TIMEOUT_INTERVAL seconds (5 by default) then the test will be marked as failed, so the test will pass (and continue to the next one) only if the promise failed.

});
});
});
Expand Down