summaryrefslogtreecommitdiff
path: root/test/specs/core/createError.spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/specs/core/createError.spec.js')
-rw-r--r--test/specs/core/createError.spec.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/specs/core/createError.spec.js b/test/specs/core/createError.spec.js
new file mode 100644
index 0000000..53f708b
--- /dev/null
+++ b/test/specs/core/createError.spec.js
@@ -0,0 +1,29 @@
+var createError = require('../../../lib/core/createError');
+
+describe('core::createError', function() {
+ it('should create an Error with message, config, code, request, response and isAxiosError', function() {
+ var request = { path: '/foo' };
+ var response = { status: 200, data: { foo: 'bar' } };
+ var error = createError('Boom!', { foo: 'bar' }, 'ESOMETHING', request, response);
+ expect(error instanceof Error).toBe(true);
+ expect(error.message).toBe('Boom!');
+ expect(error.config).toEqual({ foo: 'bar' });
+ expect(error.code).toBe('ESOMETHING');
+ expect(error.request).toBe(request);
+ expect(error.response).toBe(response);
+ expect(error.isAxiosError).toBe(true);
+ });
+ it('should create an Error that can be serialized to JSON', function() {
+ // Attempting to serialize request and response results in
+ // TypeError: Converting circular structure to JSON
+ var request = { path: '/foo' };
+ var response = { status: 200, data: { foo: 'bar' } };
+ var error = createError('Boom!', { foo: 'bar' }, 'ESOMETHING', request, response);
+ var json = error.toJSON();
+ expect(json.message).toBe('Boom!');
+ expect(json.config).toEqual({ foo: 'bar' });
+ expect(json.code).toBe('ESOMETHING');
+ expect(json.request).toBe(undefined);
+ expect(json.response).toBe(undefined);
+ });
+});