@@ -59,7 +59,7 @@ describe("withGlobal", function () {
59
59
} ) ;
60
60
61
61
describe ( "globally configured browser objects" , function ( ) {
62
- let withGlobal , originalDescriptors ;
62
+ let withGlobal , originalDescriptors , originalNavigatorDescriptor ;
63
63
64
64
// We use a set up function instead of beforeEach to avoid Mocha's check leaks detector
65
65
function setUpGlobal ( ) {
@@ -69,6 +69,11 @@ describe("globally configured browser objects", function () {
69
69
) ;
70
70
const window = dom . window ;
71
71
72
+ originalNavigatorDescriptor = Object . getOwnPropertyDescriptor (
73
+ global ,
74
+ "navigator" ,
75
+ ) ;
76
+
72
77
function makeMutable ( descriptor ) {
73
78
descriptor . configurable = true ;
74
79
}
@@ -88,6 +93,8 @@ describe("globally configured browser objects", function () {
88
93
89
94
global . window = window ;
90
95
global . document = window . document ;
96
+ // navigator is a getter, so we need to remove it, as assigning does not work
97
+ delete global . navigator ;
91
98
global . navigator = window . navigator ;
92
99
global . requestAnimationFrame = function ( callback ) {
93
100
return setTimeout ( callback , 0 ) ;
@@ -114,6 +121,15 @@ describe("globally configured browser objects", function () {
114
121
delete global . navigator ;
115
122
delete global . requestAnimationFrame ;
116
123
delete global . cancelAnimationFrame ;
124
+
125
+ // restore
126
+ if ( originalNavigatorDescriptor ) {
127
+ Object . defineProperty (
128
+ global ,
129
+ "navigator" ,
130
+ originalNavigatorDescriptor ,
131
+ ) ;
132
+ }
117
133
}
118
134
119
135
it ( "correctly instantiates and tears down" , function ( ) {
0 commit comments