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
The Rails Doctrine Decade
koic
2
440
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
410
Workers Cache を知る
syumai
0
320
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
1k
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
180
すこし踏み込む CancellationToken
htkym
2
1.5k
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.2k
FreeBSDでZabbixを動かす
kenkino
0
340
速習iPhone Duo対応
yuukiw00w
2
920
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
120
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
660
Featured
See All Featured
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Navigating Team Friction
lara
192
16k
Navigating Weather and Climate Data
rabernat
0
540
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
The Pragmatic Product Professional
lauravandoore
37
7.5k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
330
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
310
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
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