fix some missing assertions (#16336)
These were discovered by @SimenB in https://github.com/facebook/react/pull/16332. We weren't making actual assertions on some values. This PR makes the assertions, and fixes the tests.
Sunil Pai committed
Aug 9, 2019 at 15:34 UTC
f62b53d9085157717e09a19c82bfd63e8b60e09b
2 files changed
+12
-15
packages/react-dom/src/__tests__/ReactDOMComponent-test.js
+12
-14
@@ -1034,13 +1034,13 @@ describe('ReactDOMComponent', () => {
1034
return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, '\\$1');
1035
}
1036
1037
- function toHaveAttribute(actual, expected) {
1037
+ function expectToHaveAttribute(actual, expected) {
1038
const [attr, value] = expected;
1039
let re = '(?:^|\\s)' + attr + '=[\\\'"]';
1040
if (typeof value !== 'undefined') {
1041
re += quoteRegexp(value) + '[\\\'"]';
1042
}
1043
- return new RegExp(re).test(actual);
1043
+ expect(new RegExp(re).test(actual)).toBe(true);
1044
}
1045
1046
function genMarkup(props) {
@@ -1048,19 +1048,17 @@ describe('ReactDOMComponent', () => {
1048
}
1049
1050
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', '']);
1054
});
1055
1056
it('should escape style names and values', () => {
1057
- expect(
1058
- toHaveAttribute(
1059
- genMarkup({
1060
- style: {'b&ckground': '<3'},
1061
- }),
1062
- ['style', 'b&ckground:<3;'],
1063
- ),
1057
+ expectToHaveAttribute(
1058
+ genMarkup({
1059
+ style: {'b&ckground': '<3'},
1060
+ }),
1061
+ ['style', 'b&ckground:<3'],
1062
);
1063
});
1064
});
@@ -1075,7 +1073,7 @@ describe('ReactDOMComponent', () => {
1073
}
1074
1075
function toHaveInnerhtml(actual, expected) {
1078
- const re = '^' + quoteRegexp(expected) + '$';
1076
+ const re = quoteRegexp(expected);
1077
return new RegExp(re).test(actual);
1078
}
1079
@@ -1086,7 +1084,7 @@ describe('ReactDOMComponent', () => {
1084
genMarkup({dangerouslySetInnerHTML: innerHTML}),
1085
'testContent',
1086
),
1089
- );
1087
+ ).toBe(true);
1088
});
1089
});
1090
packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js
-1
@@ -660,7 +660,6 @@ describe('ReactLazy', () => {
660
// Mount
661
await Promise.resolve();
662
expect(() => {
663
- expect(Scheduler);
663
Scheduler.unstable_flushAll();
664
}).toWarnDev([
665
'Invalid prop `inner` of type `string` supplied to `Add`, expected `number`.',