Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mocha
Search
Kaneko Takeshi
December 21, 2017
Technology
49
0
Share
Mocha
Kaneko Takeshi
December 21, 2017
More Decks by Kaneko Takeshi
See All by Kaneko Takeshi
オープンソースライセンスについて勉強する定期
tkckaneko
0
38
Eye Tracking on the Browser
tkckaneko
0
93
IEEE754を完全に理解した
tkckaneko
1
83
CSSのトレンドをみんなで見よう -2021年-
tkckaneko
0
99
多分これが一番早いと思います
tkckaneko
0
29
暗黒面の話
tkckaneko
0
30
CSR / SSR / SSG / JAMstack
tkckaneko
0
77
BOLT
tkckaneko
0
38
CSS Logical Properties and Values
tkckaneko
0
49
Other Decks in Technology
See All in Technology
Claude Codeを組織で使いこなす— サーバサイドAIエージェント運用の実践知
techtekt
PRO
0
180
「気づいたら仕事が終わっている」バクラクAIエージェント本番運用の裏側 / layerx-bakuraku-aie2026
yuya4
17
8.9k
GoとSIMDとWasmの今。
askua
3
480
最低限これだけ押さえれ大丈夫_Claude Enterprise/Team企業展開ガバナンス入門
tkikuchi
1
710
AI駆動開発でなんでもハンズオン環境をつくってみた
yoshimi0227
0
200
Spring AI × MCP 入門〜AIエージェントへのツール公開、境界設計から始める最小構成 〜
yuyamiyamoto
0
210
AI時代の私の技術インプットとアウトプット術
tonkotsuboy_com
16
8.3k
Strands Agents超入門
kintotechdev
1
160
Javaコミュニティをもっと楽しむための9箇条
takasyou
0
1.2k
Gradle×GitHub_ActionsでCI時間を約50%短縮 ジョブ分割の設計と落とし穴 / Cutting CI Time by ~50% with Gradle and GitHub Actions: Job-Splitting Design and Pitfalls
takatty
0
610
Mastering Ruby Box
tagomoris
3
140
long-running-tasks
cipepser
3
460
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Designing Powerful Visuals for Engaging Learning
tmiket
1
390
A Tale of Four Properties
chriscoyier
163
24k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
210
The World Runs on Bad Software
bkeepers
PRO
72
12k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
410
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
260
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
190
Building Adaptive Systems
keathley
44
3k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Transcript
Mocha
None
テストツールの話をします
Mocha - JavaScriptのユニットテストフレームワーク - node.jsやブラウザから実行できる - IDE(WebStormなど)からも実行できる
Mocha 設定もコードも簡単にできます。 chaiやshould.jsなどのアサーションライブラリを使えば、 いろいろな書き方もできますが、今回は話しません。
準備 $ yarn add -D mocha
準備 package.json “scripts”: { “test”: “mocha” }
準備 $ yarn test
簡単な例 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); }); }); });
簡単な例 $ mocha "test/test01.js" Array #indexOf() ✓ should return -1
when the value is not present 1 passing (8ms) ✨ Done in 0.50s.
非同期の例 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); }) });
非同期の例 $ mocha "test/test02.js" async test ✓ Promise 1 passing
(12ms) ✨ Done in 0.46s.
ブラウザでも動きます
ブラウザの例 <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>
ブラウザの例
テストの結果を 変えることもできます
reporter $ yarn test --reporter json
reporter $ mocha "test/test01.js" "--reporter" "json" { "stats": { "tests":
[ { } ], "pending": [], "failures": [], ・・・ ✨ Done in 0.45s.
独自のreporter 作り方について詳しくはこちら https://github.com/mochajs/mocha/wiki/Third-party-reporters
独自のreporter $ yarn test --reporter ne
独自のreporter
おしまい いつか公開します。。。