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