Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Mocha + ES6
- ** Setup
- Run the following shell commands:
- #+BEGIN_SRC sh
- yarn init
- yarn add --dev mocha chai babel-cli babel-preset-es2015 babel-preset-flow babel-plugin-transform-class-properties flow-typed flow-bin
- #+END_SRC
- Open up =package.json= and set your test script to the following:
- =mocha --watch --compilers js:babel-core/register=
- Create a =.babelrc= file in the project directory:
- #+BEGIN_SRC js
- {
- "presets": ["flow", "es2015"],
- "plugins": ["transform-class-properties"]
- }
- #+END_SRC
- ** Example sources
- #+BEGIN_SRC js
- // test/main.test.js
- //@flow
- import { expect } from 'chai';
- import Main from '../src/main';
- describe('Main', () => {
- it('should be a class', () => {
- expect(new Main()).to.not.equal(undefined);
- });
- });
- #+END_SRC
- #+BEGIN_SRC js
- // src/main.js
- //@flow
- export default class Main {
- constructor() {
- }
- }
- #+END_SRC
- ** Example output
- #+BEGIN_SRC sh
- > yarn test
- Main
- ✓ should be a class
- 1 passing (12ms)
- #+END_SRC
- ** Setting up Flow and Flow-typed
- Flow-typed creates library definitions for third-party code (like Mocha) so Flow's able to check your tests. To set it up, first initialize Flow in your project and then install library definitions by running the following commands:
- #+BEGIN_SRC sh
- > yarn flow init
- > yarn flow-typed install
- #+END_SRC
- *** Example Usage
- #+BEGIN_SRC sh
- > yarn flow
- No errors!
- ✨ Done in 3.34s.
- #+END_SRC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement