Tip: JavaScript Date クラスを Jest でモックする方法
Takahiro Iwasa
(岩佐 孝浩)
1 min read
Jest
Jest で new Date()
をモックする方法を探していました。 fake timers と setSystemTime
を以下のように使用できます。
jest.useFakeTimers().setSystemTime(new Date('2023-01-02 12:34:56'));
Jest で new Date()
をモックする方法を探していました。 fake timers と setSystemTime
を以下のように使用できます。
jest.useFakeTimers().setSystemTime(new Date('2023-01-02 12:34:56'));
Takahiro Iwasa (岩佐 孝浩)
Software Developer at iret, Inc.
主に AWS を利用したクラウドネイティブアプリケーションの設計および開発をしています。
Japan AWS Top Engineers 2020-2023