Skip to content

Commit

Permalink
Move shared objects out of every test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 17, 2019
1 parent 0ca772c commit 87d022b
Showing 1 changed file with 11 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ describe('when Trusted Types are available in global object', () => {
let ReactDOM;
let ReactFeatureFlags;
let container;
let fakeTTObjects;
let ttObject1;
let ttObject2;

beforeEach(() => {
jest.resetModules();
container = document.createElement('div');
const fakeTTObjects = new Set();
window.trustedTypes = {
isHTML: value => fakeTTObjects.has(value),
isScript: () => false,
Expand All @@ -28,27 +30,25 @@ describe('when Trusted Types are available in global object', () => {
ReactFeatureFlags.enableTrustedTypesIntegration = true;
React = require('react');
ReactDOM = require('react-dom');
fakeTTObjects = new Set();
});

afterEach(() => {
delete window.trustedTypes;
});

it('should not stringify trusted values for dangerouslySetInnerHTML', () => {
const ttObject1 = {
ttObject1 = {
toString() {
return '<b>Hi</b>';
},
};
const ttObject2 = {
ttObject2 = {
toString() {
return '<b>Bye</b>';
},
};
fakeTTObjects.add(ttObject1);
fakeTTObjects.add(ttObject2);
});

afterEach(() => {
delete window.trustedTypes;
});

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

it('should not stringify trusted values for setAttribute (unknown attribute)', () => {
const ttObject1 = {
toString() {
return '<b>Hi</b>';
},
};
const ttObject2 = {
toString() {
return '<b>Bye</b>';
},
};
fakeTTObjects.add(ttObject1);
fakeTTObjects.add(ttObject2);

let setAttribute = Element.prototype.setAttribute;
try {
const setAttributeCalls = [];
Expand Down Expand Up @@ -133,19 +120,6 @@ describe('when Trusted Types are available in global object', () => {
});

it('should not stringify trusted values for setAttribute (known attribute)', () => {
const ttObject1 = {
toString() {
return '<b>Hi</b>';
},
};
const ttObject2 = {
toString() {
return '<b>Bye</b>';
},
};
fakeTTObjects.add(ttObject1);
fakeTTObjects.add(ttObject2);

let setAttribute = Element.prototype.setAttribute;
try {
const setAttributeCalls = [];
Expand Down Expand Up @@ -174,19 +148,6 @@ describe('when Trusted Types are available in global object', () => {
});

it('should not stringify trusted values for setAttributeNS', () => {
const ttObject1 = {
toString() {
return '<b>Hi</b>';
},
};
const ttObject2 = {
toString() {
return '<b>Bye</b>';
},
};
fakeTTObjects.add(ttObject1);
fakeTTObjects.add(ttObject2);

let setAttributeNS = Element.prototype.setAttributeNS;
try {
const setAttributeNSCalls = [];
Expand Down

0 comments on commit 87d022b

Please sign in to comment.