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
39
Mocha
Kaneko Takeshi
December 21, 2017
Tweet
Share
More Decks by Kaneko Takeshi
See All by Kaneko Takeshi
オープンソースライセンスについて勉強する定期
tkckaneko
0
10
Eye Tracking on the Browser
tkckaneko
0
71
IEEE754を完全に理解した
tkckaneko
1
50
CSSのトレンドをみんなで見よう -2021年-
tkckaneko
0
69
多分これが一番早いと思います
tkckaneko
0
23
暗黒面の話
tkckaneko
0
14
CSR / SSR / SSG / JAMstack
tkckaneko
0
50
BOLT
tkckaneko
0
10
CSS Logical Properties and Values
tkckaneko
0
24
Other Decks in Technology
See All in Technology
MySQL の SQL クエリチューニングの要所を掴む勉強会
andpad
2
6.3k
複雑な構成要素を持つUIとの向き合い方 〜新・支出グラフでの実例〜 / B43 TECH TALK
nakamuuu
0
140
GraphQL 成熟度モデルの紹介と、プロダクトに当てはめた事例 / GraphQL maturity model
mh4gf
7
1.3k
Databricks における 『MLOps』
databricksjapan
2
170
ServiceNow Knowledge Learning Rise up
manarobot
0
210
エンジニアのキャリアをちょっと楽しくする3本の軸/Three Pillars to Make an Engineer's Career More Enjoyable
kwappa
0
2.7k
レガシーをぶっ壊せ。AEONで始めるDevRelの話 / Qiita Night 2024-2-22
aeonpeople
3
1.3k
プラットフォームってつくることより計測することが重要なんじゃないかという話 / Platform Engineering Meetup #8
taishin
1
350
家族アルバム みてねにおけるGrafana活用術 / Grafana Meetup Japan Vol.1 LT
isaoshimizu
1
670
TechFeed Experts Night#27 〜 フロントエンドフレームワーク最前線 (Svelte)
baseballyama
1
470
Gitlab本から学んだこと - そーだいなるプレイバック / gitlab-book
soudai
4
360
FrontDoorとWebAppsを組み合わせた際のリダイレクト処理の注意点
kenichirokimura
1
510
Featured
See All Featured
Side Projects
sachag
451
41k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
241
1.2M
Docker and Python
trallard
34
2.7k
The Invisible Side of Design
smashingmag
294
49k
Six Lessons from altMBA
skipperchong
21
3k
Building a Modern Day E-commerce SEO Strategy
aleyda
17
6.4k
Web Components: a chance to create the future
zenorocha
305
41k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
116
18k
RailsConf 2023
tenderlove
4
540
KATA
mclloyd
15
12k
Typedesign – Prime Four
hannesfritz
36
2.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
243
12k
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
おしまい いつか公開します。。。