File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
packages/jest-environment-jsdom/src Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 6
6
7
7
### Fixes
8
8
9
+ - ` [jest-environment-jsdom] ` Add support for ` userAgent ` option ([ #11773 ] ( https://github.com/facebook/jest/pull/11773 ) )
9
10
- ` [jest-environment-node] ` Add ` Event ` and ` EventTarget ` to node global environment. ([ #11705 ] ( https://github.com/facebook/jest/issues/11705 ) )
10
11
- ` [jest-mock] ` Fix ` spyOn ` to use ` Object.prototype.hasOwnProperty ` [ #11721 ] ( https://github.com/facebook/jest/pull/11721 )
11
12
- ` [jest-resolver] ` Add dependency on ` jest-haste-map ` [ #11759 ] ( https://github.com/facebook/jest/pull/11759 )
Original file line number Diff line number Diff line change @@ -27,4 +27,16 @@ describe('JSDomEnvironment', () => {
27
27
28
28
expect ( env . fakeTimersModern ) . toBeDefined ( ) ;
29
29
} ) ;
30
+
31
+ it ( 'should respect userAgent option' , ( ) => {
32
+ const env = new JSDomEnvironment (
33
+ makeProjectConfig ( {
34
+ testEnvironmentOptions : {
35
+ userAgent : 'foo' ,
36
+ } ,
37
+ } ) ,
38
+ ) ;
39
+
40
+ expect ( env . dom . window . navigator . userAgent ) . toEqual ( 'foo' ) ;
41
+ } ) ;
30
42
} ) ;
Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
import type { Context } from 'vm' ;
9
- import { JSDOM , VirtualConsole } from 'jsdom' ;
9
+ import { JSDOM , ResourceLoader , VirtualConsole } from 'jsdom' ;
10
10
import type { EnvironmentContext , JestEnvironment } from '@jest/environment' ;
11
11
import { LegacyFakeTimers , ModernFakeTimers } from '@jest/fake-timers' ;
12
12
import type { Config , Global } from '@jest/types' ;
@@ -33,6 +33,12 @@ class JSDOMEnvironment implements JestEnvironment {
33
33
constructor ( config : Config . ProjectConfig , options ?: EnvironmentContext ) {
34
34
this . dom = new JSDOM ( '<!DOCTYPE html>' , {
35
35
pretendToBeVisual : true ,
36
+ resources :
37
+ typeof config . testEnvironmentOptions . userAgent === 'string'
38
+ ? new ResourceLoader ( {
39
+ userAgent : config . testEnvironmentOptions . userAgent ,
40
+ } )
41
+ : undefined ,
36
42
runScripts : 'dangerously' ,
37
43
url : config . testURL ,
38
44
virtualConsole : new VirtualConsole ( ) . sendTo ( options ?. console || console ) ,
You can’t perform that action at this time.
0 commit comments