Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mocha

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 Mocha

Avatar for Kaneko Takeshi

Kaneko Takeshi

December 21, 2017
Tweet

More Decks by Kaneko Takeshi

Other Decks in Technology

Transcript

  1. 簡単な例 var assert = require('assert'); describe('Array', function() { describe('#indexOf()', function()

    { it('should return -1 when the value is not present', function() { assert.equal([1,2,3].indexOf(4), -1); }); }); });
  2. 簡単な例 $ mocha "test/test01.js" Array #indexOf() ✓ should return -1

    when the value is not present 1 passing (8ms) ✨ Done in 0.50s.
  3. 非同期の例 const assert = require('assert'); function asyncAdd(a, b) { return

    new Promise((resolve) => { resolve(a+b); }); }; describe('async test', () => { it('Promise', (done) => { let result = 0; asyncAdd(2, 3).then((result) => { assert(result === 9); }).then(done, done); }) });
  4. ブラウザの例 <html> <head> <meta charset="utf-8"> <title>Mocha Tests</title> <link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet"

    /> </head> <body> <div id="mocha"></div> <script src="https://cdn.rawgit.com/jquery/jquery/2.1.4/dist/jquery.min.js"></script> <script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script> <script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script> <script>mocha.setup('bdd')</script>
  5. reporter $ mocha "test/test01.js" "--reporter" "json" { "stats": { "tests":

    [ { } ], "pending": [], "failures": [], ・・・ ✨ Done in 0.45s.