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.
This commit is contained in:
Sunil Pai
2019-08-09 15:34:49 +01:00
committed by GitHub
parent b9faa3b092
commit f62b53d908
2 changed files with 12 additions and 15 deletions
+12 -14
View File
@@ -1034,13 +1034,13 @@ 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) {
@@ -1048,19 +1048,17 @@ describe('ReactDOMComponent', () => {
}
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'],
);
});
});
@@ -1075,7 +1073,7 @@ describe('ReactDOMComponent', () => {
}
function toHaveInnerhtml(actual, expected) {
const re = '^' + quoteRegexp(expected) + '$';
const re = quoteRegexp(expected);
return new RegExp(re).test(actual);
}
@@ -1086,7 +1084,7 @@ describe('ReactDOMComponent', () => {
genMarkup({dangerouslySetInnerHTML: innerHTML}),
'testContent',
),
);
).toBe(true);
});
});
@@ -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`.',