Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. * Mocha + ES6
  2. ** Setup
  3. Run the following shell commands:
  4. #+BEGIN_SRC sh
  5. yarn init
  6. yarn add --dev mocha chai babel-cli babel-preset-es2015 babel-preset-flow babel-plugin-transform-class-properties flow-typed flow-bin
  7. #+END_SRC
  8.  
  9. Open up =package.json= and set your test script to the following:
  10. =mocha --watch --compilers js:babel-core/register=
  11.  
  12. Create a =.babelrc= file in the project directory:
  13. #+BEGIN_SRC js
  14. {
  15. "presets": ["flow", "es2015"],
  16. "plugins": ["transform-class-properties"]
  17. }
  18. #+END_SRC
  19. ** Example sources
  20. #+BEGIN_SRC js
  21. // test/main.test.js
  22. //@flow
  23. import { expect } from 'chai';
  24.  
  25. import Main from '../src/main';
  26.  
  27. describe('Main', () => {
  28.  
  29. it('should be a class', () => {
  30. expect(new Main()).to.not.equal(undefined);
  31. });
  32.  
  33. });
  34. #+END_SRC
  35.  
  36. #+BEGIN_SRC js
  37. // src/main.js
  38. //@flow
  39. export default class Main {
  40. constructor() {
  41. }
  42. }
  43. #+END_SRC
  44. ** Example output
  45. #+BEGIN_SRC sh
  46. > yarn test
  47.  
  48. Main
  49. ✓ should be a class
  50.  
  51.  
  52. 1 passing (12ms)
  53. #+END_SRC
  54.  
  55. ** Setting up Flow and Flow-typed
  56. 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:
  57.  
  58. #+BEGIN_SRC sh
  59. > yarn flow init
  60. > yarn flow-typed install
  61. #+END_SRC
  62.  
  63. *** Example Usage
  64. #+BEGIN_SRC sh
  65. > yarn flow
  66. No errors!
  67. ✨ Done in 3.34s.
  68. #+END_SRC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement