首页 > 其他分享 >[Unit testing] Vitest, mock Time

[Unit testing] Vitest, mock Time

时间:2023-09-27 21:44:06浏览次数:37  
标签:Vitest render vi testing afterEach Time test import

import { afterEach, test, expect, vi, beforeEach } from 'vitest';
import { render } from 'test/utilities';
import TimeZone from '.';

beforeEach(() => {
  // freeze time
  vi.useFakeTimers();
  // set system time to a certain point
  vi.setSystemTime(1679492355195);
});

test('it should render successfully', () => {
  render(<TimeZone />);
});

test('should match the snapshot', async () => {
  const { container } = render(<TimeZone />);
  expect(container).toMatchSnapshot();
});

afterEach(() => {
  vi.useRealTimers();
});

 

标签:Vitest,render,vi,testing,afterEach,Time,test,import
From: https://www.cnblogs.com/Answer1215/p/17734413.html

相关文章

  • 后端传递Timestamp类型时间前端自定义接收格式
    Vue项目中处理后端返回日期字符串在这个Vue项目中,后端接口RentalQueryAllServlet返回的租车记录数据中,有一个rentalTime字段,其值是日期字符串,如:"Sep27,20239:23:40AM"。1.获取数据组件中使用axios调用接口获取数据: js methods:{fetchData(){axio......
  • Python datetime 的坑以及时间处理的经验
    最近遇到一个"bug",就是本地datetime的时间上传到数据库,总发现时间显示不对……经过一番痛苦的排查之后,我发现原来是datetime.now()在获取事件信息时,不会添加当前的时区信息。也就是说,获得的结果虽然时分秒和电脑显示一致,但是时区信息为默认的UTC而非我们真正的UTC+8,因此这......
  • 成功实现FaceTime语音,FaceTime视频,FaceTime数据筛选,检测手机号是否开通FaceTime的
    FaceTime是苹果公司iOS和macOS(以前称MacOSX或OSX)内置的一款视频通话软件,通过Wi-Fi或者蜂窝数据接入互联网,在两个装有FaceTime的设备之间实现视频通话。其要求通话双方均具有装有FaceTime的苹果设备,苹果ID以及可接入互联网的3G/4G/5G或者Wi-Fi网络。 一、Windows电脑上部署......
  • Python RuntimeError: dictionary changed size during iteration
    运行下面代码,报如下错误fornameinglobals():print(name) 解决办法是:将待遍历的对象转换成列表fornameinlist(globals()):print(name) ......
  • DateTime
    点击查看代码usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;publicclassProgram{publicstaticvoidMain(){vars=TimeSpan.FromHours(24);Console.WriteLine(s);//1.00:00:00Console.WriteLin......
  • 【SmartApi】设置超时时间timeout
    在内测几个版本后,有用户反应设置请求超时时间过于麻烦和不直观,于是在和大家交流后把这个功能提上日程,事实上这个功能设置还是很简单的,于是就在请求面板里添加了一个timeout选项卡,如下图:具体使用如下:1、选择一个api请求,点击“timeout”选项卡如下图:2、这里有两项功能,第一个是......
  • Winform中使用System.Windows.Forms.Timer多次启动停止计时器时绑定事件会重复多次执
    场景C#中实现计时器功能(定时任务和计时多长时间后执行某方法):https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/106274074以上关于定时器的使用。在实现点击按钮启动定时器,点击停止按钮停止定时器时发现,重复多次后会导致定时器方法累计重复执行。联想到如下情况......
  • linux教程:/usr/bin/time -f “time: %E“命令解释
    /usr/bin/time-f"time:%E"是一个命令行命令,用于在Linux系统上以自定义格式显示命令的执行时间。该命令使用了GNUtime工具,而不是shell的内置time命令。解释一下各个部分的含义:/usr/bin/time:这是GNUtime工具的路径。在大多数Linux系统上,time工具的可执行文件位于/usr/bin/time......
  • mybatis plus生成的日期时间格式LocalDateTime与String的相互转换
    mybatisplus生成的日期时间格式为LocalDateTime LocalDateTime转为String:将现在的时间转StringStringnowDate=LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss"))  将指定的String日期转DatetimeLocalDateTimeldatetime=Lo......
  • Java:JSR 310日期时间体系LocalDateTime、OffsetDateTime、ZonedDateTime
    JSR310日期时间体系:LocalDateTime:本地日期时间OffsetDateTime:带偏移量的日期时间ZonedDateTime:带时区的日期时间(目录)日期时间包importjava.time.LocalDateTime;importjava.time.OffsetDateTime;importjava.time.ZonedDateTime;importjava.time.format.DateTimeF......