@@ -3,13 +3,6 @@ import { GatsbyImage, IGatsbyImageData } from "../gatsby-image.browser"
3
3
import { render , waitFor } from "@testing-library/react"
4
4
import * as hooks from "../hooks"
5
5
6
- type GlobalOverride = NodeJS . Global &
7
- typeof global . globalThis & {
8
- // eslint-disable-next-line @typescript-eslint/naming-convention
9
- GATSBY___IMAGE : boolean
10
- SERVER : boolean
11
- }
12
-
13
6
// Prevents terser for bailing because we're not in a babel plugin
14
7
jest . mock ( `../../../macros/terser.macro` , ( ) => ( strs ) : string => strs . join ( `` ) )
15
8
@@ -19,8 +12,9 @@ describe(`GatsbyImage browser`, () => {
19
12
20
13
beforeEach ( ( ) => {
21
14
console . warn = jest . fn ( )
22
- ; ( global as GlobalOverride ) . SERVER = true
23
- ; ( global as GlobalOverride ) . GATSBY___IMAGE = true
15
+ console . error = jest . fn ( )
16
+ global . SERVER = true
17
+ global . GATSBY___IMAGE = true
24
18
} )
25
19
26
20
beforeEach ( ( ) => {
@@ -73,20 +67,20 @@ describe(`GatsbyImage browser`, () => {
73
67
74
68
afterEach ( ( ) => {
75
69
jest . clearAllMocks ( )
76
- ; ( global as GlobalOverride ) . SERVER = undefined
77
- ; ( global as GlobalOverride ) . GATSBY___IMAGE = undefined
70
+ global . SERVER = undefined
71
+ global . GATSBY___IMAGE = undefined
78
72
} )
79
73
80
74
it ( `shows a suggestion to switch to the new gatsby-image API when available` , async ( ) => {
81
- ; ( global as GlobalOverride ) . GATSBY___IMAGE = false
75
+ global . GATSBY___IMAGE = undefined
82
76
83
77
const { container } = render (
84
78
< GatsbyImage image = { image } alt = "Alt content" />
85
79
)
86
80
87
81
await waitFor ( ( ) => container . querySelector ( `[data-placeholder-image=""]` ) )
88
82
89
- expect ( console . warn ) . toBeCalledWith (
83
+ expect ( console . error ) . toBeCalledWith (
90
84
`[gatsby-plugin-image] You're missing out on some cool performance features. Please add "gatsby-plugin-image" to your gatsby-config.js`
91
85
)
92
86
} )
@@ -164,7 +158,7 @@ describe(`GatsbyImage browser`, () => {
164
158
container . querySelector ( `[data-main-image=""]` )
165
159
)
166
160
167
- img . dispatchEvent ( new Event ( `load` ) )
161
+ img ? .dispatchEvent ( new Event ( `load` ) )
168
162
169
163
expect ( onStartLoadSpy ) . toBeCalledWith ( { wasCached : false } )
170
164
expect ( onLoadSpy ) . toBeCalled ( )
0 commit comments