mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 01:16:18 -05:00
29 lines
891 B
JavaScript
29 lines
891 B
JavaScript
|
|
jest.mock('web-vitals', () => ({
|
||
|
|
onCLS: jest.fn(),
|
||
|
|
onINP: jest.fn(),
|
||
|
|
onFCP: jest.fn(),
|
||
|
|
onLCP: jest.fn(),
|
||
|
|
onTTFB: jest.fn(),
|
||
|
|
}));
|
||
|
|
|
||
|
|
import reportWebVitals from './reportWebVitals';
|
||
|
|
import * as webVitals from 'web-vitals';
|
||
|
|
|
||
|
|
describe('reportWebVitals', () => {
|
||
|
|
test('subscribes the callback to every current web-vitals metric', async () => {
|
||
|
|
const callback = jest.fn();
|
||
|
|
const pending = reportWebVitals(callback);
|
||
|
|
expect(pending).toBeDefined();
|
||
|
|
await pending;
|
||
|
|
for (const name of ['onCLS', 'onINP', 'onFCP', 'onLCP', 'onTTFB']) {
|
||
|
|
expect(webVitals[name]).toHaveBeenCalledWith(callback);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('does nothing without a function', async () => {
|
||
|
|
jest.clearAllMocks();
|
||
|
|
expect(reportWebVitals(undefined)).toBeUndefined();
|
||
|
|
expect(webVitals.onCLS).not.toHaveBeenCalled();
|
||
|
|
});
|
||
|
|
});
|