Skip to content

Commit

Permalink
capricorn86#722@patch: Use performance.now in tests
Browse files Browse the repository at this point in the history
Co-authored-by: David Ortner <david@ortner.se>
  • Loading branch information
aripalo and capricorn86 committed Feb 9, 2023
1 parent 20b07ac commit 96646dc
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions packages/happy-dom/test/event/Event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@ describe('Event', () => {
window.customElements.define('custom-element', CustomElement);
});

describe('timeStamp', () => {
it('Has a timeStamp property.', () => {
const event = new Event('click');
expect('timeStamp' in event).toBeTruthy();
});
it('Property is of type number.', () => {
const event = new Event('click');
expect(typeof event.timeStamp).toBe('number');
});
it('Has value greater than zero.', () => {
const event = new Event('click');
expect(event.timeStamp).toBeGreaterThan(0);
});
it('Returns a value not in the future', () => {
afterEach(() => {
jest.restoreAllMocks();
});

describe('get timeStamp()', () => {
it('Returns the value returned by performance.now() at the time it was created.', () => {
const performanceNow = 12345;
spyOn(performance, 'now').mockImplementation(() => performanceNow);
const event = new Event('click');
const { timeOrigin } = performance;
const eventOriginalTime = timeOrigin + event.timeStamp;
const now = Date.now();
expect(eventOriginalTime).toBeLessThanOrEqual(now);
expect(event.timeStamp).toBe(performanceNow);
});
});

Expand Down

0 comments on commit 96646dc

Please sign in to comment.