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
320
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
100
競プロへの誘 -いざな-
u76ner
0
1k
Other Decks in Programming
See All in Programming
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
790
Building a Meta Ray-Ban display app
akkeylab
0
160
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.7k
SlackアプリとLambdaの 連携を構築した話
pawn_4_s
1
120
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
4.5k
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
590
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
500
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
240
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
290
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
930
バグを直したら useEffect が消えた
colorful12
2
100
Featured
See All Featured
Fireside Chat
paigeccino
42
4k
Speed Design
sergeychernyshev
33
2k
How to make the Groovebox
asonas
2
2.3k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
940
Navigating Team Friction
lara
192
16k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
240
Java REST API Framework Comparison - PWX 2021
mraible
34
9.6k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
890
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
430
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
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