more consistent jest time mocks

This commit is contained in:
or-else
2025-07-30 18:12:55 +03:00
parent 9eba65b711
commit 7ce9470bf3
8 changed files with 14 additions and 25 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "tinode-webapp", "name": "tinode-webapp",
"description": "Tinode messenger for the web", "description": "Tinode messenger for the web",
"version": "0.24.2", "version": "0.24.3",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/tinode/webapp.git" "url": "git+https://github.com/tinode/webapp.git"
+7 -18
View File
@@ -9,15 +9,9 @@ import {
} from './strformat.js'; } from './strformat.js';
describe('shortDateFormat', () => { describe('shortDateFormat', () => {
const now = new Date('2025-07-25T12:30:00'); jest
// Mock Date.now .useFakeTimers()
let dateNowSpy; .setSystemTime(new Date('2025-07-25T12:30:00Z'));
beforeAll(() => {
dateNowSpy = jest.spyOn(Date, 'now').mockImplementation(() => now.getTime());
});
afterAll(() => {
dateNowSpy.mockRestore();
});
test('should format for same day', () => { test('should format for same day', () => {
const then = new Date('2025-07-25T10:15:00'); const then = new Date('2025-07-25T10:15:00');
@@ -38,15 +32,10 @@ describe('shortDateFormat', () => {
}); });
describe('relativeDateFormat', () => { describe('relativeDateFormat', () => {
const now = new Date('2025-07-25T12:30:00Z'); // Mock current date to a fixed point for consistent testing.
// Mock Date.now jest
let dateNowSpy; .useFakeTimers()
beforeAll(() => { .setSystemTime(new Date('2025-07-25T12:30:00Z'));
dateNowSpy = jest.spyOn(Date, 'now').mockImplementation(() => now.getTime());
});
afterAll(() => {
dateNowSpy.mockRestore();
});
test('should format for today', () => { test('should format for today', () => {
const then = new Date('2025-07-25T10:00:00Z'); const then = new Date('2025-07-25T10:00:00Z');
+1 -1
View File
@@ -1,3 +1,3 @@
// This is a generated file. Don't edit. // This is a generated file. Don't edit.
export const PACKAGE_VERSION = "0.24.2"; export const PACKAGE_VERSION = "0.24.3";
+1 -1
View File
@@ -8655,7 +8655,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ PACKAGE_VERSION: function() { return /* binding */ PACKAGE_VERSION; } /* harmony export */ PACKAGE_VERSION: function() { return /* binding */ PACKAGE_VERSION; }
/* harmony export */ }); /* harmony export */ });
const PACKAGE_VERSION = "0.24.2"; const PACKAGE_VERSION = "0.24.3";
/***/ }), /***/ }),
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,3 +1,3 @@
// This is a generated file. Don't edit. // This is a generated file. Don't edit.
const PACKAGE_VERSION = "0.24.2"; const PACKAGE_VERSION = "0.24.3";