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
マンガアプリViewerの大画面対応を考える
kk__777
0
440
Designing Repeatable Edits: The Architecture of . in Vim
satorunooshie
0
220
Pythonに漸進的に型をつける
nealle
1
150
AkarengaLT vol.38
hashimoto_kei
1
130
SODA - FACT BOOK(JP)
sodainc
1
9.1k
AsyncSequenceとAsyncStreamのプロポーザルを全部読む!!
s_shimotori
1
220
Module Proxyのマニアックな話 / Niche Topics in Module Proxy
kuro_kurorrr
0
1k
MCPサーバー「モディフィウス」で変更容易性の向上をスケールする / modifius
minodriven
3
130
Register is more than clipboard
satorunooshie
1
340
React Nativeならぬ"Vue Native"が実現するかも?_新世代マルチプラットフォーム開発フレームワークのLynxとLynxのVue.js対応を追ってみよう_Vue Lynx
yut0naga1_fa
2
2k
When Dependencies Fail: Building Antifragile Applications in a Fragile World
selcukusta
0
120
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
200
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
340
57k
Writing Fast Ruby
sferik
630
62k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
950
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Product Roadmaps are Hard
iamctodd
PRO
55
11k
Unsuck your backbone
ammeep
671
58k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
A better future with KSS
kneath
239
18k
Docker and Python
trallard
46
3.6k
Stop Working from a Prison Cell
hatefulcrawdad
272
21k
Into the Great Unknown - MozCon
thekraken
40
2.1k
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