forked from adoptium/adoptium.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vitest-setup.ts
120 lines (107 loc) · 2.65 KB
/
vitest-setup.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { expect, vi } from 'vitest'
import * as axeMatchers from 'vitest-axe/matchers'
import React from 'react'
import matchers from '@testing-library/jest-dom/matchers';
import 'vitest-axe/extend-expect'
import '@testing-library/jest-dom'
expect.extend(axeMatchers);
expect.extend(matchers);
vi.mock('gatsby', async () => {
const gatsby = await vi.importActual<typeof import('gatsby')>('gatsby')
const mockUseStaticQuery = {
site: {
siteMetadata: {
title: 'Sample Title',
description: 'Sample Description',
siteUrl: 'https://sample.com',
}
},
avatar: {
edges: [
{
node: {
name: 'pmc',
childImageSharp: {
gatsbyImageData: {
layout: 'fixed',
images: {
fallback: {
src: 'https://sample-images.com/pmc.png',
}
}
}
}
}
}
]
},
mdx: {
frontmatter: {
author: 'pmc',
}
}
}
return {
...gatsby,
graphql: vi.fn(),
StaticQuery: vi.fn(),
useStaticQuery: vi.fn().mockImplementation(() => mockUseStaticQuery)
}
})
vi.mock('gatsby-plugin-image', async () => {
const plugin = await vi.importActual<typeof import('gatsby-plugin-image')>('gatsby-plugin-image')
const mockImage = ({imgClassName, imgStyle, ...props}: any) => {
return React.createElement('img', {
className: imgClassName,
stlye: imgStyle,
...props
})
}
const mockPlugin = {
...plugin,
GatsbyImage: vi.fn().mockImplementation(mockImage),
StaticImage: vi.fn().mockImplementation(mockImage),
}
return mockPlugin
})
vi.mock('@reach/router', async () => {
return {
useLocation: () => ({
pathname: '/'
})
}
})
vi.mock('react-world-flags', async () => {
return {
default: () => 'Flag'
}
})
vi.mock('gatsby-plugin-react-i18next', async () => {
return {
Link: vi.fn().mockImplementation(({ to, getProps, ...rest }) =>
React.createElement('a', {
...rest,
href: to
})
),
useTranslation: () => ({
t: (key: string) => key,
i18n: {
changeLanguage: async () => await new Promise(() => {})
}
}),
useI18next: () => ({
language: 'en',
languages: ['en', 'en-GB', 'es', 'de', 'zh-CN'],
changeLanguage: async () => await new Promise(() => {})
}),
Trans: () => 'Text'
}
})
const IntersectionObserverMock = vi.fn(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
takeRecords: vi.fn(),
unobserve: vi.fn()
}))
vi.stubGlobal('IntersectionObserver', IntersectionObserverMock)