Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Commit b771f41

Browse files
pratap0007tekton-robot
authored andcommitted
Fix to mock both Date and Date.mow()
This fixes mock Date in the test and snapshots Signed-off-by: Shiv Verma <shverma@redhat.com>
1 parent 1c6d26d commit b771f41

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

ui/src/common/testutils.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
//Sets a Fake date for test
1+
const RealDate = global.Date;
2+
const FIXED = new RealDate('2026-01-01T10:20:30Z');
3+
24
export const FakeDate = () => {
35
beforeEach(() => {
4-
global.Date.now = jest.fn(() => new Date('2021-01-01T10:20:30Z').getTime());
6+
global.Date = class extends RealDate {
7+
constructor(...args: [number?]) {
8+
super(args[0] ?? FIXED.getTime());
9+
}
10+
static now = () => FIXED.getTime();
11+
} as DateConstructor;
512
});
6-
};
7-
8-
//Sets an Actual date for test
9-
export const ActualDate = () => {
1013
afterEach(() => {
11-
global.Date = Date;
14+
global.Date = RealDate;
1215
});
1316
};
17+
18+
export const ActualDate = () => {};

ui/src/components/Footer/__snapshots__/Footer.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`should render the footer component 1`] = `
66
<Grid>
77
<GridItem span={12} className=\\"hub-footer-info\\">
88
<a href=\\"https://cd.foundation\\" target=\\"_\\">
9-
<img src=\\"https://tekton.dev/partner-logos/cdf.png?1609496430000\\" alt=\\"tekton.dev\\" />
9+
<img src=\\"https://tekton.dev/partner-logos/cdf.png?1767262830000\\" alt=\\"tekton.dev\\" />
1010
</a>
1111
</GridItem>
1212
<GridItem span={12} className=\\"hub-footer-info\\">
@@ -23,12 +23,12 @@ exports[`should render the footer component 1`] = `
2323
</TextContent>
2424
</GridItem>
2525
<GridItem span={12} className=\\"hub-logo-margin\\">
26-
<img src=\\"tekton.png?1609496430000\\" alt=\\"Tekton\\" className=\\"hub-logo-size\\" />
26+
<img src=\\"tekton.png?1767262830000\\" alt=\\"Tekton\\" className=\\"hub-logo-size\\" />
2727
</GridItem>
2828
<GridItem span={12} className=\\"hub-footer-description\\">
2929
<Text>
3030
©
31-
2025
31+
2026
3232
The Linux Foundation®. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our
3333
3434
<Text component=\\"a\\" href=\\"https://www.linuxfoundation.org/trademark-usage/\\" target=\\"_\\">

ui/src/containers/App/__snapshots__/App.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ exports[`App should render the component correctly and match the snapshot 1`] =
348348
<GridItem span={12} className=\\"hub-footer-info\\">
349349
<div className=\\"pf-l-grid__item pf-m-12-col hub-footer-info\\" style={[undefined]}>
350350
<a href=\\"https://cd.foundation\\" target=\\"_\\">
351-
<img src=\\"https://tekton.dev/partner-logos/cdf.png?1609496430000\\" alt=\\"tekton.dev\\" />
351+
<img src=\\"https://tekton.dev/partner-logos/cdf.png?1767262830000\\" alt=\\"tekton.dev\\" />
352352
</a>
353353
</div>
354354
</GridItem>
@@ -375,15 +375,15 @@ exports[`App should render the component correctly and match the snapshot 1`] =
375375
</GridItem>
376376
<GridItem span={12} className=\\"hub-logo-margin\\">
377377
<div className=\\"pf-l-grid__item pf-m-12-col hub-logo-margin\\" style={[undefined]}>
378-
<img src=\\"tekton.png?1609496430000\\" alt=\\"Tekton\\" className=\\"hub-logo-size\\" />
378+
<img src=\\"tekton.png?1767262830000\\" alt=\\"Tekton\\" className=\\"hub-logo-size\\" />
379379
</div>
380380
</GridItem>
381381
<GridItem span={12} className=\\"hub-footer-description\\">
382382
<div className=\\"pf-l-grid__item pf-m-12-col hub-footer-description\\" style={[undefined]}>
383383
<Text>
384384
<p data-ouia-component-type=\\"PF4/Text\\" data-ouia-safe={true} data-ouia-component-id=\\"OUIA-Generated-Text-11\\" data-pf-content={true} className=\\"\\">
385385
©
386-
2025
386+
2026
387387
The Linux Foundation®. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our
388388
389389
<Text component=\\"a\\" href=\\"https://www.linuxfoundation.org/trademark-usage/\\" target=\\"_\\">

0 commit comments

Comments
 (0)