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
0
300
mockdateええやん
WASD Inc. LT会(仮)
2022-01-14
U76NER
January 14, 2022
Tweet
Share
More Decks by U76NER
See All by U76NER
JSのクラスの後ろ向きな話
u76ner
0
130
GASええやん
u76ner
1
89
競プロへの誘 -いざな-
u76ner
0
920
Other Decks in Programming
See All in Programming
CSC305 Lecture 05
javiergs
PRO
0
210
なぜGoのジェネリクスはこの形なのか? Featherweight Goが明かす設計の核心
ryotaros
7
1.1k
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
250
登壇は dynamic! な営みである / speech is dynamic
da1chi
0
300
Advance Your Career with Open Source
ivargrimstad
0
490
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
240
Serena MCPのすすめ
wadakatu
4
980
理論と実務のギャップを超える
eycjur
0
130
非同期jobをtransaction内で 呼ぶなよ!絶対に呼ぶなよ!
alstrocrack
0
720
詳しくない分野でのVibe Codingで困ったことと学び/vibe-coding-in-unfamiliar-area
shibayu36
3
4.9k
バッチ処理を「状態の記録」から「事実の記録」へ
panda728
PRO
0
150
Writing Better Go: Lessons from 10 Code Reviews
konradreiche
0
800
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
54
3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
Designing Experiences People Love
moore
142
24k
GraphQLとの向き合い方2022年版
quramy
49
14k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
590
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
Making Projects Easy
brettharned
119
6.4k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
189
55k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
53k
How to train your dragon (web standard)
notwaldorf
96
6.3k
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