Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
mockdateええやん
Search
U76NER
January 14, 2022
Programming
330
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
110
競プロへの誘 -いざな-
u76ner
0
1k
Other Decks in Programming
See All in Programming
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
260
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1k
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
410
AHC070解法紹介
eijirou
0
150
iOSDCのペンライトを自動制御したい!
akkeylab
0
280
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
280
SREの越境 / SRE Collaboration
y0hgi
2
290
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
170
アクセシビリティから考える情報設計
high_g_engineer
0
430
Heart of Swift Concurrency
koher
0
1.1k
カツオ、ご期待ください
suneo3476
0
130
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
290
Thoughts on Productivity
jonyablonski
76
5.4k
How to train your dragon (web standard)
notwaldorf
97
6.8k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
The Language of Interfaces
destraynor
162
27k
Everyday Curiosity
cassininazir
0
340
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
450
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Skip the Path - Find Your Career Trail
mkilby
1
240
A better future with KSS
kneath
240
18k
Into the Great Unknown - MozCon
thekraken
41
2.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