mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
+12
-14
@@ -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&ckground:<3;'],
|
||||
),
|
||||
expectToHaveAttribute(
|
||||
genMarkup({
|
||||
style: {'b&ckground': '<3'},
|
||||
}),
|
||||
['style', 'b&ckground:<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`.',
|
||||
|
||||
Reference in New Issue
Block a user