目次
実装
以下のようにテストコードを実装すると
test("日付変更テスト", async () => {
// 日付を2023年1月1日に変更
vi.setSystemTime(new Date("2023-01-01T00:00:00.000Z"));
const { getByText } = setup(<View />);
});
以下のDateが2023年1月1日で取得することができます。
import React from 'react';
const View = () => {
const date = new Date();
console.log(date); // 2023-01-01T00:00:00.000Z
return <h1>bbbaaa</h1>;
};
export default View;