Skip to content

Commit 87d022b

Browse files
committed
Move shared objects out of every test
1 parent 0ca772c commit 87d022b

File tree

1 file changed

+11
-50
lines changed

1 file changed

+11
-50
lines changed

packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ describe('when Trusted Types are available in global object', () => {
1414
let ReactDOM;
1515
let ReactFeatureFlags;
1616
let container;
17-
let fakeTTObjects;
17+
let ttObject1;
18+
let ttObject2;
1819

1920
beforeEach(() => {
2021
jest.resetModules();
2122
container = document.createElement('div');
23+
const fakeTTObjects = new Set();
2224
window.trustedTypes = {
2325
isHTML: value => fakeTTObjects.has(value),
2426
isScript: () => false,
@@ -28,27 +30,25 @@ describe('when Trusted Types are available in global object', () => {
2830
ReactFeatureFlags.enableTrustedTypesIntegration = true;
2931
React = require('react');
3032
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 = {
4034
toString() {
4135
return '<b>Hi</b>';
4236
},
4337
};
44-
const ttObject2 = {
38+
ttObject2 = {
4539
toString() {
4640
return '<b>Bye</b>';
4741
},
4842
};
4943
fakeTTObjects.add(ttObject1);
5044
fakeTTObjects.add(ttObject2);
45+
});
46+
47+
afterEach(() => {
48+
delete window.trustedTypes;
49+
});
5150

51+
it('should not stringify trusted values for dangerouslySetInnerHTML', () => {
5252
let innerHTMLDescriptor = Object.getOwnPropertyDescriptor(
5353
Element.prototype,
5454
'innerHTML',
@@ -92,19 +92,6 @@ describe('when Trusted Types are available in global object', () => {
9292
});
9393

9494
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-
10895
let setAttribute = Element.prototype.setAttribute;
10996
try {
11097
const setAttributeCalls = [];
@@ -133,19 +120,6 @@ describe('when Trusted Types are available in global object', () => {
133120
});
134121

135122
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-
149123
let setAttribute = Element.prototype.setAttribute;
150124
try {
151125
const setAttributeCalls = [];
@@ -174,19 +148,6 @@ describe('when Trusted Types are available in global object', () => {
174148
});
175149

176150
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-
190151
let setAttributeNS = Element.prototype.setAttributeNS;
191152
try {
192153
const setAttributeNSCalls = [];

0 commit comments

Comments
 (0)