Skip to content

Fix #494: Reject a promise on error condition #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/ParseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,8 @@ var DefaultController = {
}, options);
}).then((response, status, xhr) => {
batchReturned.resolve(response, status);
}, (error) => {
batchReturned.reject(new ParseError(ParseError.INCORRECT_TYPE, error.message));
});

return ParsePromise.when(batchTasks);
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/ParseObject-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,19 @@ describe('ParseObject', () => {
});
});

it('should fail on invalid date', (done) => {
var obj = new ParseObject('Item');
obj.set('when', new Date(Date.parse(null)));
ParseObject.saveAll([obj]).then(() => {
done.fail('Expected invalid date to fail');
}).fail((error) => {
expect(error[0].code).toEqual(ParseError.INCORRECT_TYPE);
expect(error[0].message).toEqual('Tried to encode an invalid date.');
done();
});
jest.runAllTicks();
});

it('can save a ring of objects, given one exists', (done) => {
var xhrs = [];
RESTController._setXHR(function() {
Expand Down