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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kaneko Takeshi
December 21, 2017
Technology
0
47
Mocha
Kaneko Takeshi
December 21, 2017
Tweet
Share
More Decks by Kaneko Takeshi
See All by Kaneko Takeshi
オープンソースライセンスについて勉強する定期
tkckaneko
0
34
Eye Tracking on the Browser
tkckaneko
0
91
IEEE754を完全に理解した
tkckaneko
1
79
CSSのトレンドをみんなで見よう -2021年-
tkckaneko
0
96
多分これが一番早いと思います
tkckaneko
0
28
暗黒面の話
tkckaneko
0
27
CSR / SSR / SSG / JAMstack
tkckaneko
0
74
BOLT
tkckaneko
0
33
CSS Logical Properties and Values
tkckaneko
0
38
Other Decks in Technology
See All in Technology
1GB RAMのラズピッピで何ができるのか試してみよう / 20260319-rpijam-1gb-rpi-whats-possible
akkiesoft
0
530
会社紹介資料 / Sansan Company Profile
sansan33
PRO
16
410k
NewSQL_ ストレージ分離と分散合意を用いたスケーラブルアーキテクチャ
hacomono
PRO
4
410
中央集権型を脱却した話 分散型をやめて、連邦型にたどり着くまで
sansantech
PRO
1
110
AI実装による「レビューボトルネック」を解消する仕様駆動開発(SDD)/ ai-sdd-review-bottleneck
rakus_dev
0
160
Goのerror型がシンプルであることの恩恵について理解する
yamatai1212
1
250
大規模ECサイトのあるバッチのパフォーマンスを改善するために僕たちのチームがしてきたこと
panda_program
1
130
システム標準化PMOから ガバメントクラウドCoEへ
techniczna
1
140
ReactのdangerouslySetInnerHTMLは“dangerously”だから危険 / Security.any #09 卒業したいセキュリティLT
flatt_security
0
320
Claude Code Skills 勉強会 (DevelersIO向けに調整済み) / claude code skills for devio
masahirokawahara
1
22k
社内レビューは機能しているのか
matsuba
0
150
It’s “Time” to use Temporal
sajikix
3
230
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
Navigating Weather and Climate Data
rabernat
0
140
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.4k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.1k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
95
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
860
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
450
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
The Limits of Empathy - UXLibs8
cassininazir
1
270
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
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
おしまい いつか公開します。。。