Skip to content

Commit eac45e9

Browse files
claudijoflovilmart
authored andcommitted
Add sensible string representation of ParseError objects (#406)
1 parent bf20e99 commit eac45e9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/ParseError.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export default class ParseError {
1919
this.code = code;
2020
this.message = message;
2121
}
22+
23+
toString() {
24+
return 'ParseError: ' + this.code + ' ' + this.message;
25+
}
2226
}
2327

2428
/**

src/__tests__/ParseError-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
jest.dontMock('../ParseError');
11+
12+
var ParseError = require('../ParseError').default;
13+
14+
describe('ParseError', () => {
15+
it('have sensible string representation', () => {
16+
var error = new ParseError(123, 'some error message');
17+
18+
expect(error.toString()).toMatch('ParseError');
19+
expect(error.toString()).toMatch('123');
20+
expect(error.toString()).toMatch('some error message');
21+
});
22+
});

0 commit comments

Comments
 (0)