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
mockdateええやん
Search
U76NER
January 14, 2022
Programming
320
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
mockdateええやん
WASD Inc. LT会(仮)
2022-01-14
U76NER
January 14, 2022
More Decks by U76NER
See All by U76NER
JSのクラスの後ろ向きな話
u76ner
0
140
GASええやん
u76ner
1
100
競プロへの誘 -いざな-
u76ner
0
1k
Other Decks in Programming
See All in Programming
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
200
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4k
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
180
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
520
New "Type" system on PicoRuby
pocke
1
780
Swiftのレキシカルスコープ管理
kntkymt
0
220
RTSPクライアントを自作してみた話
simotin13
0
520
CSC307 Lecture 17
javiergs
PRO
0
320
Claspは野良GASの夢をみるか
takter00
0
180
AIエージェントの隔離技術の徹底比較
kawayu
0
470
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
230
Oxlintのカスタムルールの現況
syumai
6
1k
Featured
See All Featured
Paper Plane (Part 1)
katiecoart
PRO
0
8.8k
Test your architecture with Archunit
thirion
1
2.3k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
610
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
310
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Statistics for Hackers
jakevdp
799
230k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Transcript
mockdateええやん LT会(仮) 2022/01/14 u76ner
時刻を使った関数 2 - 時刻を使った関数を書くことはよくある - 例)現在時刻が2022/1/14より早い日付かどうかを返す関数
テストどうすんねん問題 3 - テストを実行する時刻によって結果が変わってしまう - テストが書けない ?????????????
今までどうしてたか 4 - 現在時刻を引数に渡すことでテストを書いてた - デフォルト値で現在時刻を書いておけば使う分には意識しなくて良い
だけども 5 - まず使うことはない引数を書いておくのはよくなさそう - 意図しない使い方をされる
- 引数増やすときの順番を間違える 無理やり引数渡されて…シテ...状態になった関数くん 順序逆だよ
だけども 6 - まず使うことはない引数を書いておくのはよくなさそう - 別の関数で使うときに引数を渡し忘れる こうなると人間が頑張ってミスを見つけるしかない
mockdate 7 - mockdate - https://www.npmjs.com/package/mockdate - テストを実行するときの時刻を固定できるライブラリ
- 中の実装もシンプルで面白い - よいところ - dayjsとかを使っててもok - dayjsも結局中身はDateなので - 使い方が超楽
mockdate 8 - 使い方は超楽 - 使う前にset() - 使った後にreset() -
これだけ
こんな感じでどうでしょう 9 - 時刻ごとにdescribeでまとめると書きやすいかも?
10