Skip to content

Commit f62b53d

Browse files
author
Sunil Pai
authored
fix some missing assertions (#16336)
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.
1 parent b9faa3b commit f62b53d

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

packages/react-dom/src/__tests__/ReactDOMComponent-test.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,33 +1034,31 @@ describe('ReactDOMComponent', () => {
10341034
return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, '\\$1');
10351035
}
10361036

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

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

10501050
it('should generate the correct markup with className', () => {
1051-
expect(toHaveAttribute(genMarkup({className: 'a'}), ['class', 'a']));
1052-
expect(toHaveAttribute(genMarkup({className: 'a b'}), ['class', 'a b']));
1053-
expect(toHaveAttribute(genMarkup({className: ''}), ['class', '']));
1051+
expectToHaveAttribute(genMarkup({className: 'a'}), ['class', 'a']);
1052+
expectToHaveAttribute(genMarkup({className: 'a b'}), ['class', 'a b']);
1053+
expectToHaveAttribute(genMarkup({className: ''}), ['class', '']);
10541054
});
10551055

10561056
it('should escape style names and values', () => {
1057-
expect(
1058-
toHaveAttribute(
1059-
genMarkup({
1060-
style: {'b&ckground': '<3'},
1061-
}),
1062-
['style', 'b&amp;ckground:&lt;3;'],
1063-
),
1057+
expectToHaveAttribute(
1058+
genMarkup({
1059+
style: {'b&ckground': '<3'},
1060+
}),
1061+
['style', 'b&amp;ckground:&lt;3'],
10641062
);
10651063
});
10661064
});
@@ -1075,7 +1073,7 @@ describe('ReactDOMComponent', () => {
10751073
}
10761074

10771075
function toHaveInnerhtml(actual, expected) {
1078-
const re = '^' + quoteRegexp(expected) + '$';
1076+
const re = quoteRegexp(expected);
10791077
return new RegExp(re).test(actual);
10801078
}
10811079

@@ -1086,7 +1084,7 @@ describe('ReactDOMComponent', () => {
10861084
genMarkup({dangerouslySetInnerHTML: innerHTML}),
10871085
'testContent',
10881086
),
1089-
);
1087+
).toBe(true);
10901088
});
10911089
});
10921090

packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ describe('ReactLazy', () => {
660660
// Mount
661661
await Promise.resolve();
662662
expect(() => {
663-
expect(Scheduler);
664663
Scheduler.unstable_flushAll();
665664
}).toWarnDev([
666665
'Invalid prop `inner` of type `string` supplied to `Add`, expected `number`.',

0 commit comments

Comments
 (0)