Now I found jest-cli on a video on Egghead.io with Kent C. Dodds, which does the job of my unittest of ES6 classes.
1) install npm dependencies. Download package.json and run npm install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "ject", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "jest" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"babel-preset-es2015": "^6.18.0", | |
"jest-cli": "^17.0.3" | |
}, | |
"dependencies": { | |
"babel-jest": "^17.0.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"presets": ["es2015"] | |
} |
3) save following content to your root as sum.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test { | |
constructor(x, y) { | |
this.x = x; | |
this.y = y; | |
} | |
sum(a, b) { | |
return a+b; | |
} | |
} | |
export default Test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by pboethig on 07.12.16. | |
*/ | |
import Test from './sum'; | |
test('1 + 2 = 3', ()=> | |
{ | |
var inst = new Test(1,2); | |
inst.sum(1,2) | |
}); | |
5) run npm test
That`s all. Now you are able to test ES6 classes. Here are the souces on github: https://github.com/pboethig/unittest-es6-javascript
Keine Kommentare:
Kommentar veröffentlichen