@@ -18,14 +18,20 @@ import {
18
18
} from '../../../../test/utils' ;
19
19
import { createAlgoliaInsightsPlugin } from '../createAlgoliaInsightsPlugin' ;
20
20
21
- beforeEach ( ( ) => {
22
- ( window as any ) . AlgoliaAnalyticsObject = undefined ;
23
- ( window as any ) . aa = undefined ;
21
+ describe ( 'createAlgoliaInsightsPlugin' , ( ) => {
22
+ const originalWindow = global . window ;
24
23
25
- document . body . innerHTML = '' ;
26
- } ) ;
24
+ beforeEach ( ( ) => {
25
+ ( window as any ) . AlgoliaAnalyticsObject = undefined ;
26
+ ( window as any ) . aa = undefined ;
27
+
28
+ document . body . innerHTML = '' ;
29
+ } ) ;
30
+
31
+ afterEach ( ( ) => {
32
+ global . window = originalWindow ;
33
+ } ) ;
27
34
28
- describe ( 'createAlgoliaInsightsPlugin' , ( ) => {
29
35
test ( 'has a name' , ( ) => {
30
36
const plugin = createAlgoliaInsightsPlugin ( { insightsClient } ) ;
31
37
@@ -343,6 +349,17 @@ describe('createAlgoliaInsightsPlugin', () => {
343
349
'[Autocomplete]: Could not load search-insights.js. Please load it manually following https://alg.li/insights-autocomplete'
344
350
) ;
345
351
} ) ;
352
+
353
+ it ( 'does not throw in server environments' , ( ) => {
354
+ // @ts -expect-error
355
+ delete global . window ;
356
+
357
+ expect ( ( ) => {
358
+ createPlayground ( createAutocomplete , {
359
+ plugins : [ createAlgoliaInsightsPlugin ( { } ) ] ,
360
+ } ) ;
361
+ } ) . not . toThrow ( ) ;
362
+ } ) ;
346
363
} ) ;
347
364
348
365
describe ( 'onItemsChange' , ( ) => {
0 commit comments