@@ -14,11 +14,13 @@ describe('when Trusted Types are available in global object', () => {
14
14
let ReactDOM ;
15
15
let ReactFeatureFlags ;
16
16
let container ;
17
- let fakeTTObjects ;
17
+ let ttObject1 ;
18
+ let ttObject2 ;
18
19
19
20
beforeEach ( ( ) => {
20
21
jest . resetModules ( ) ;
21
22
container = document . createElement ( 'div' ) ;
23
+ const fakeTTObjects = new Set ( ) ;
22
24
window . trustedTypes = {
23
25
isHTML : value => fakeTTObjects . has ( value ) ,
24
26
isScript : ( ) => false ,
@@ -28,27 +30,25 @@ describe('when Trusted Types are available in global object', () => {
28
30
ReactFeatureFlags . enableTrustedTypesIntegration = true ;
29
31
React = require ( 'react' ) ;
30
32
ReactDOM = require ( 'react-dom' ) ;
31
- fakeTTObjects = new Set ( ) ;
32
- } ) ;
33
-
34
- afterEach ( ( ) => {
35
- delete window . trustedTypes ;
36
- } ) ;
37
-
38
- it ( 'should not stringify trusted values for dangerouslySetInnerHTML' , ( ) => {
39
- const ttObject1 = {
33
+ ttObject1 = {
40
34
toString ( ) {
41
35
return '<b>Hi</b>' ;
42
36
} ,
43
37
} ;
44
- const ttObject2 = {
38
+ ttObject2 = {
45
39
toString ( ) {
46
40
return '<b>Bye</b>' ;
47
41
} ,
48
42
} ;
49
43
fakeTTObjects . add ( ttObject1 ) ;
50
44
fakeTTObjects . add ( ttObject2 ) ;
45
+ } ) ;
46
+
47
+ afterEach ( ( ) => {
48
+ delete window . trustedTypes ;
49
+ } ) ;
51
50
51
+ it ( 'should not stringify trusted values for dangerouslySetInnerHTML' , ( ) => {
52
52
let innerHTMLDescriptor = Object . getOwnPropertyDescriptor (
53
53
Element . prototype ,
54
54
'innerHTML' ,
@@ -92,19 +92,6 @@ describe('when Trusted Types are available in global object', () => {
92
92
} ) ;
93
93
94
94
it ( 'should not stringify trusted values for setAttribute (unknown attribute)' , ( ) => {
95
- const ttObject1 = {
96
- toString ( ) {
97
- return '<b>Hi</b>' ;
98
- } ,
99
- } ;
100
- const ttObject2 = {
101
- toString ( ) {
102
- return '<b>Bye</b>' ;
103
- } ,
104
- } ;
105
- fakeTTObjects . add ( ttObject1 ) ;
106
- fakeTTObjects . add ( ttObject2 ) ;
107
-
108
95
let setAttribute = Element . prototype . setAttribute ;
109
96
try {
110
97
const setAttributeCalls = [ ] ;
@@ -133,19 +120,6 @@ describe('when Trusted Types are available in global object', () => {
133
120
} ) ;
134
121
135
122
it ( 'should not stringify trusted values for setAttribute (known attribute)' , ( ) => {
136
- const ttObject1 = {
137
- toString ( ) {
138
- return '<b>Hi</b>' ;
139
- } ,
140
- } ;
141
- const ttObject2 = {
142
- toString ( ) {
143
- return '<b>Bye</b>' ;
144
- } ,
145
- } ;
146
- fakeTTObjects . add ( ttObject1 ) ;
147
- fakeTTObjects . add ( ttObject2 ) ;
148
-
149
123
let setAttribute = Element . prototype . setAttribute ;
150
124
try {
151
125
const setAttributeCalls = [ ] ;
@@ -174,19 +148,6 @@ describe('when Trusted Types are available in global object', () => {
174
148
} ) ;
175
149
176
150
it ( 'should not stringify trusted values for setAttributeNS' , ( ) => {
177
- const ttObject1 = {
178
- toString ( ) {
179
- return '<b>Hi</b>' ;
180
- } ,
181
- } ;
182
- const ttObject2 = {
183
- toString ( ) {
184
- return '<b>Bye</b>' ;
185
- } ,
186
- } ;
187
- fakeTTObjects . add ( ttObject1 ) ;
188
- fakeTTObjects . add ( ttObject2 ) ;
189
-
190
151
let setAttributeNS = Element . prototype . setAttributeNS ;
191
152
try {
192
153
const setAttributeNSCalls = [ ] ;
0 commit comments