Skip to content

Commit dd20b4b

Browse files
nrchandanflovilmart
authored andcommitted
Fix #494: Reject a promise on error condition (#495)
1 parent 4a6e619 commit dd20b4b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/ParseObject.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,8 @@ var DefaultController = {
18121812
}, options);
18131813
}).then((response, status, xhr) => {
18141814
batchReturned.resolve(response, status);
1815+
}, (error) => {
1816+
batchReturned.reject(new ParseError(ParseError.INCORRECT_TYPE, error.message));
18151817
});
18161818

18171819
return ParsePromise.when(batchTasks);

src/__tests__/ParseObject-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,19 @@ describe('ParseObject', () => {
11151115
});
11161116
});
11171117

1118+
it('should fail on invalid date', (done) => {
1119+
var obj = new ParseObject('Item');
1120+
obj.set('when', new Date(Date.parse(null)));
1121+
ParseObject.saveAll([obj]).then(() => {
1122+
done.fail('Expected invalid date to fail');
1123+
}).fail((error) => {
1124+
expect(error[0].code).toEqual(ParseError.INCORRECT_TYPE);
1125+
expect(error[0].message).toEqual('Tried to encode an invalid date.');
1126+
done();
1127+
});
1128+
jest.runAllTicks();
1129+
});
1130+
11181131
it('can save a ring of objects, given one exists', (done) => {
11191132
var xhrs = [];
11201133
RESTController._setXHR(function() {

0 commit comments

Comments
 (0)