Skip to content

Commit

Permalink
fix some missing assertions (#16336)
Browse files Browse the repository at this point in the history
These were discovered by @SimenB in #16332. We weren't making actual assertions on some values. This PR makes the assertions, and fixes the tests.
  • Loading branch information
Sunil Pai authored Aug 9, 2019
1 parent b9faa3b commit f62b53d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
26 changes: 12 additions & 14 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,33 +1034,31 @@ describe('ReactDOMComponent', () => {
return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, '\\$1');
}

function toHaveAttribute(actual, expected) {
function expectToHaveAttribute(actual, expected) {
const [attr, value] = expected;
let re = '(?:^|\\s)' + attr + '=[\\\'"]';
if (typeof value !== 'undefined') {
re += quoteRegexp(value) + '[\\\'"]';
}
return new RegExp(re).test(actual);
expect(new RegExp(re).test(actual)).toBe(true);
}

function genMarkup(props) {
return ReactDOMServer.renderToString(<div {...props} />);
}

it('should generate the correct markup with className', () => {
expect(toHaveAttribute(genMarkup({className: 'a'}), ['class', 'a']));
expect(toHaveAttribute(genMarkup({className: 'a b'}), ['class', 'a b']));
expect(toHaveAttribute(genMarkup({className: ''}), ['class', '']));
expectToHaveAttribute(genMarkup({className: 'a'}), ['class', 'a']);
expectToHaveAttribute(genMarkup({className: 'a b'}), ['class', 'a b']);
expectToHaveAttribute(genMarkup({className: ''}), ['class', '']);
});

it('should escape style names and values', () => {
expect(
toHaveAttribute(
genMarkup({
style: {'b&ckground': '<3'},
}),
['style', 'b&amp;ckground:&lt;3;'],
),
expectToHaveAttribute(
genMarkup({
style: {'b&ckground': '<3'},
}),
['style', 'b&amp;ckground:&lt;3'],
);
});
});
Expand All @@ -1075,7 +1073,7 @@ describe('ReactDOMComponent', () => {
}

function toHaveInnerhtml(actual, expected) {
const re = '^' + quoteRegexp(expected) + '$';
const re = quoteRegexp(expected);
return new RegExp(re).test(actual);
}

Expand All @@ -1086,7 +1084,7 @@ describe('ReactDOMComponent', () => {
genMarkup({dangerouslySetInnerHTML: innerHTML}),
'testContent',
),
);
).toBe(true);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ describe('ReactLazy', () => {
// Mount
await Promise.resolve();
expect(() => {
expect(Scheduler);
Scheduler.unstable_flushAll();
}).toWarnDev([
'Invalid prop `inner` of type `string` supplied to `Add`, expected `number`.',
Expand Down

0 comments on commit f62b53d

Please sign in to comment.