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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
U76NER
January 14, 2022
Programming
320
0
Share
mockdateええやん
WASD Inc. LT会(仮)
2022-01-14
U76NER
January 14, 2022
More Decks by U76NER
See All by U76NER
JSのクラスの後ろ向きな話
u76ner
0
130
GASええやん
u76ner
1
99
競プロへの誘 -いざな-
u76ner
0
980
Other Decks in Programming
See All in Programming
実用!Hono RPC2026
yodaka
2
290
【26新卒研修資料】TDD実装演習
dip_tech
PRO
0
160
なぜあなたのコードには「コシ」がないのか?〜AI時代に問う、最後まで美味しい設計と戦略〜 #phpconkagawa / phpconkagawa2026
shogogg
0
110
GitHubCopilotCLIをはじめよう.pdf
htkym
0
310
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
3
970
Making the RBS Parser Faster
soutaro
0
650
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
230
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.5k
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
160
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
620
Vibe NLP for Applied NLP
inesmontani
PRO
0
580
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
0
310
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Rails Girls Zürich Keynote
gr2m
96
14k
Done Done
chrislema
186
16k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
21
Game over? The fight for quality and originality in the time of robots
wayneb77
1
170
Evolving SEO for Evolving Search Engines
ryanjones
0
190
The Invisible Side of Design
smashingmag
302
52k
Navigating Team Friction
lara
192
16k
Chasing Engaging Ingredients in Design
codingconduct
0
180
Designing Experiences People Love
moore
143
24k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
500
Leo the Paperboy
mayatellez
7
1.7k
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