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
0
47
Mocha
Kaneko Takeshi
December 21, 2017
Tweet
Share
More Decks by Kaneko Takeshi
See All by Kaneko Takeshi
オープンソースライセンスについて勉強する定期
tkckaneko
0
26
Eye Tracking on the Browser
tkckaneko
0
83
IEEE754を完全に理解した
tkckaneko
1
75
CSSのトレンドをみんなで見よう -2021年-
tkckaneko
0
92
多分これが一番早いと思います
tkckaneko
0
25
暗黒面の話
tkckaneko
0
23
CSR / SSR / SSG / JAMstack
tkckaneko
0
67
BOLT
tkckaneko
0
25
CSS Logical Properties and Values
tkckaneko
0
32
Other Decks in Technology
See All in Technology
2025-06-26_Lightning_Talk_for_Lightning_Talks
_hashimo2
2
120
KubeCon + CloudNativeCon Japan 2025 Recap by CA
ponkio_o
PRO
0
290
React開発にStorybookとCopilotを導入して、爆速でUIを編集・確認する方法
yu_kod
1
230
AI時代の開発生産性を加速させるアーキテクチャ設計
plaidtech
PRO
3
120
What’s new in Android development tools
yanzm
0
220
B2C&B2B&社内向けサービスを抱える開発組織におけるサービス価値を最大化するイニシアチブ管理
belongadmin
1
6.1k
LangSmith×Webhook連携で実現するプロンプトドリブンCI/CD
sergicalsix
1
210
無意味な開発生産性の議論から抜け出すための予兆検知とお金とAI
i35_267
3
12k
LangChain Interrupt & LangChain Ambassadors meetingレポート
os1ma
2
290
SmartNewsにおける 1000+ノード規模 K8s基盤 でのコスト最適化 – Spot・Gravitonの大規模導入への挑戦
vsanna2
0
120
生成AI時代の開発組織・技術・プロセス 〜 ログラスの挑戦と考察 〜
itohiro73
1
430
CursorによるPMO業務の代替 / Automating PMO Tasks with Cursor
motoyoshi_kakaku
2
930
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
The World Runs on Bad Software
bkeepers
PRO
69
11k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
BBQ
matthewcrist
89
9.7k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Navigating Team Friction
lara
187
15k
Bash Introduction
62gerente
614
210k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
510
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
How to Think Like a Performance Engineer
csswizardry
24
1.7k
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
おしまい いつか公開します。。。