-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathjest-setup.js
More file actions
37 lines (30 loc) · 1.12 KB
/
jest-setup.js
File metadata and controls
37 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Jest setup provided by Grafana scaffolding
import { TextDecoder, TextEncoder } from 'util';
import './.config/jest-setup';
import { toEmitValuesWith } from './tests/matchers';
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
expect.extend({
toEmitValuesWith,
});
// mock the intersection observer and just say everything is in view
const mockIntersectionObserver = jest.fn().mockImplementation((callback) => ({
disconnect: jest.fn(),
observe: jest.fn().mockImplementation((elem) => {
callback([{ isIntersecting: true, target: elem }]);
}),
unobserve: jest.fn(),
}));
global.IntersectionObserver = mockIntersectionObserver;
jest.mock('semver/preload', () => ({
...jest.requireActual('semver/preload'),
ltr: () => false,
}));
// @grafana/scenes patchGetAdhocFilters logs via console.log when the Jest env lacks full Grafana APIs.
const nativeConsoleLog = console.log.bind(console);
jest.spyOn(console, 'log').mockImplementation((first, ...rest) => {
if (typeof first === 'string' && first.includes('Failed to patch getAdhocFilters')) {
return;
}
return nativeConsoleLog(first, ...rest);
});