forked from newrelic/gatsby-theme-newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-test-env.mjs
65 lines (60 loc) · 1.54 KB
/
setup-test-env.mjs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* global expect */
import { createSerializer, matchers } from '@emotion/jest';
import * as emotion from '@emotion/react';
import '@testing-library/jest-dom';
expect.extend(matchers);
expect.addSnapshotSerializer(createSerializer(emotion));
global.ResizeObserver = class ResizeObserver {
observe = jest.fn();
disconnect = jest.fn();
};
// this mock runs after the test environment is set up,
// but before any tests run.
// any mocks need to be here, because if they're in a test file,
// the mocks aren't properly hoisted (because of ESM) and
// the module won't actually be mocked.
jest.unstable_mockModule('gatsby', () => ({
__esModule: true,
graphql: jest.fn(),
Link: jest.fn(({ to, ...props }) => <a href={to} {...props} />),
useStaticQuery: jest.fn(() => ({
allLocale: {
nodes: [
{
name: 'English',
locale: 'en',
localizedPath: '/en',
isDefault: true,
},
],
},
site: {
siteMetadata: {
siteUrl: 'https://github.com/foo/bar',
repository: 'https://foobar.net',
},
layout: { mobileBreakpoint: '500px' },
},
newRelicThemeConfig: {
tessen: {
product: 'foo',
subproduct: 'foobar',
},
},
})),
}));
// mock userAgent
Object.defineProperty(
window.navigator,
'userAgent',
((value) => ({
get() {
value =
'Mozilla/5.0 (darwin) AppleWebKit/555.56 (KHTML, like Gecko) jsdom/20.0.3';
return value;
},
set(v) {
value = v;
},
}))(window.navigator.userAgent)
);