Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.

Commit e949360

Browse files
committed
chore(tests): switch to jest
1 parent 79daa2e commit e949360

File tree

4 files changed

+622
-266
lines changed

4 files changed

+622
-266
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_js:
44
- '4'
55
- '5'
66
- '6'
7+
- '7'
78
after_success:
89
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all'
910
- python travis_after_all.py

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
"@spudly/eslint-config": "^5.0.1",
77
"babel-preset-es2015": "^6.9.0",
88
"babel-preset-stage-2": "^6.22.0",
9-
"babel-register": "^6.11.6",
109
"babelify": "^7.3.0",
1110
"browserify": "^14.0.0",
1211
"eslint": "^3.18.0",
1312
"husky": "^0.13.2",
13+
"jest": "^19.0.2",
1414
"lint-staged": "^3.4.0",
15-
"mocha": "^3.0.1",
16-
"nyc": "^10.0.0",
1715
"prettier": "^0.22.0",
1816
"semantic-release": "^6.3.2"
1917
},
@@ -25,7 +23,7 @@
2523
},
2624
"scripts": {
2725
"test": "npm run lint && npm run test-only",
28-
"test-only": "nyc --require babel-register mocha -u exports",
26+
"test-only": "jest",
2927
"build": "browserify -t [ babelify --presets [ es2015 ] ] src/ErrorSubclass.js --standalone ErrorSubclass > umd.js",
3028
"lint": "eslint src",
3129
"prepublish": "npm run build",

src/ErrorSubclass.test.js

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {doesNotThrow, equal, ok} from 'assert';
21
import ErrorSubclass from '../src/ErrorSubclass';
32

43
const ERROR_MESSAGE = '__MESSAGE__';
@@ -9,54 +8,46 @@ class SubSubError extends ErrorSubclass {
98

109
const {captureStackTrace} = Error;
1110

12-
const tests = {
13-
ErrorSubclass: {
14-
'Subclass of ErrorSubclass': {
15-
'can be instantiated': () => {
16-
doesNotThrow(() => new SubSubError(ERROR_MESSAGE));
17-
},
18-
19-
'SubSubclass instance': {
20-
afterEach() {
21-
Error.captureStackTrace = captureStackTrace;
22-
},
23-
24-
'should be instanceof Error': () => {
25-
const instance = new SubSubError(ERROR_MESSAGE);
26-
ok(instance instanceof Error);
27-
ok(instance instanceof SubSubError);
28-
},
29-
30-
'should have a name that matches the displayName': () => {
31-
const instance = new SubSubError(ERROR_MESSAGE);
32-
equal(instance.name, 'SubSubErrorDisplayName');
33-
},
34-
35-
'should have a message': () => {
36-
const instance = new SubSubError(ERROR_MESSAGE);
37-
equal(instance.message, ERROR_MESSAGE);
38-
},
39-
40-
'has a toString() method': () => {
41-
const instance = new SubSubError(ERROR_MESSAGE);
42-
equal(typeof instance.toString, 'function');
43-
equal(instance.toString(), `SubSubErrorDisplayName: ${ERROR_MESSAGE}`);
44-
},
45-
46-
'when captureStackTrace is supported, should have a stack': () => {
47-
equal(typeof Error.captureStackTrace, 'function');
48-
const instance = new SubSubError(ERROR_MESSAGE);
49-
ok(instance.stack);
50-
equal(typeof instance.stack, 'string');
51-
ok(instance.stack.match(`SubSubErrorDisplayName: ${ERROR_MESSAGE}`));
52-
}
53-
54-
// 'when captureStackTrace is not supported, should have a stack': () => {
55-
// // TODO: how to test?
56-
// },
57-
}
58-
}
59-
}
60-
};
61-
62-
export default tests;
11+
afterEach(() => {
12+
Error.captureStackTrace = captureStackTrace;
13+
});
14+
15+
test('Subclass of ErrorSubclass can be instantiated', () => {
16+
expect(() => new SubSubError(ERROR_MESSAGE)).not.toThrow();
17+
});
18+
19+
test('SubSubclass instance should be instanceof Error', () => {
20+
const instance = new SubSubError(ERROR_MESSAGE);
21+
expect(instance).toBeInstanceOf(Error);
22+
expect(instance).toBeInstanceOf(SubSubError);
23+
});
24+
25+
test('SubSubclass instance should have a name that matches the displayName', () => {
26+
const instance = new SubSubError(ERROR_MESSAGE);
27+
expect(instance.name).toBe('SubSubErrorDisplayName');
28+
});
29+
30+
test('SubSubclass instance should have a message', () => {
31+
const instance = new SubSubError(ERROR_MESSAGE);
32+
expect(instance.message).toBe(ERROR_MESSAGE);
33+
});
34+
35+
test('SubSubclass instance has a toString() method', () => {
36+
const instance = new SubSubError(ERROR_MESSAGE);
37+
expect(typeof instance.toString).toBe('function');
38+
expect(instance.toString()).toBe(`SubSubErrorDisplayName: ${ERROR_MESSAGE}`);
39+
});
40+
41+
test('SubSubclass instance when captureStackTrace is supported, should have a stack', () => {
42+
expect(typeof Error.captureStackTrace).toBe('function');
43+
const instance = new SubSubError(ERROR_MESSAGE);
44+
expect(typeof instance.stack).toBe('string');
45+
expect(instance.stack).toMatch(`SubSubErrorDisplayName: ${ERROR_MESSAGE}`);
46+
});
47+
48+
test('SubSubclass, when captureStackTrace is not supported, should still have a stack', () => {
49+
Reflect.deleteProperty(Error, 'captureStackTrace');
50+
expect(Error.captureStackTrace).not.toBeDefined();
51+
const instance = new SubSubError(ERROR_MESSAGE);
52+
expect(typeof instance.stack).toBe('string');
53+
});

0 commit comments

Comments
 (0)