Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and Sebastian Silbermann committed Jan 26, 2024
1 parent 4018999 commit 8f5e56c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
16 changes: 8 additions & 8 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3094,27 +3094,27 @@ describe('ReactDOMComponent', () => {
it('warns on the ambiguous string value "false"', function () {
let el;
expect(() => {
el = ReactTestUtils.renderIntoDocument(<div hidden="false" />);
el = ReactTestUtils.renderIntoDocument(<div disabled="false" />);
}).toErrorDev(
'Received the string `false` for the boolean attribute `hidden`. ' +
'Received the string `false` for the boolean attribute `disabled`. ' +
'The browser will interpret it as a truthy value. ' +
'Did you mean hidden={false}?',
'Did you mean disabled={false}?',
);

expect(el.getAttribute('hidden')).toBe('');
expect(el.getAttribute('disabled')).toBe('');
});

it('warns on the potentially-ambiguous string value "true"', function () {
let el;
expect(() => {
el = ReactTestUtils.renderIntoDocument(<div hidden="true" />);
el = ReactTestUtils.renderIntoDocument(<div disabled="true" />);
}).toErrorDev(
'Received the string `true` for the boolean attribute `hidden`. ' +
'Received the string `true` for the boolean attribute `disabled`. ' +
'Although this works, it will not work as expected if you pass the string "false". ' +
'Did you mean hidden={true}?',
'Did you mean disabled={true}?',
);

expect(el.getAttribute('hidden')).toBe('');
expect(el.getAttribute('disabled')).toBe('');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,71 +82,68 @@ describe('ReactDOMServerIntegration', () => {

describe('boolean properties', function () {
itRenders('boolean prop with true value', async render => {
const e = await render(<div hidden={true} />);
expect(e.getAttribute('hidden')).toBe('');
const e = await render(<div disabled={true} />);
expect(e.getAttribute('disabled')).toBe('');
});

itRenders('boolean prop with false value', async render => {
const e = await render(<div hidden={false} />);
expect(e.getAttribute('hidden')).toBe(null);
const e = await render(<div disabled={false} />);
expect(e.getAttribute('disabled')).toBe(null);
});

itRenders('boolean prop with self value', async render => {
const e = await render(<div hidden="hidden" />);
expect(e.getAttribute('hidden')).toBe('');
const e = await render(<div disabled="disabled" />);
expect(e.getAttribute('disabled')).toBe('');
});

// this does not seem like correct behavior, since hidden="" in HTML indicates
// that the boolean property is present. however, it is how the current code
// behaves, so the test is included here.
itRenders('boolean prop with "" value', async render => {
const e = await render(<div hidden="" />);
expect(e.getAttribute('hidden')).toBe(null);
const e = await render(<div disabled="" />);
expect(e.getAttribute('disabled')).toBe(null);
});

// this seems like it might mask programmer error, but it's existing behavior.
itRenders('boolean prop with string value', async render => {
const e = await render(<div hidden="foo" />);
expect(e.getAttribute('hidden')).toBe('');
const e = await render(<div disabled="foo" />);
expect(e.getAttribute('disabled')).toBe('');
});

// this seems like it might mask programmer error, but it's existing behavior.
itRenders('boolean prop with array value', async render => {
const e = await render(<div hidden={['foo', 'bar']} />);
expect(e.getAttribute('hidden')).toBe('');
const e = await render(<div disabled={['foo', 'bar']} />);
expect(e.getAttribute('disabled')).toBe('');
});

// this seems like it might mask programmer error, but it's existing behavior.
itRenders('boolean prop with object value', async render => {
const e = await render(<div hidden={{foo: 'bar'}} />);
expect(e.getAttribute('hidden')).toBe('');
const e = await render(<div disabled={{foo: 'bar'}} />);
expect(e.getAttribute('disabled')).toBe('');
});

// this seems like it might mask programmer error, but it's existing behavior.
itRenders('boolean prop with non-zero number value', async render => {
const e = await render(<div hidden={10} />);
expect(e.getAttribute('hidden')).toBe('');
const e = await render(<div disabled={10} />);
expect(e.getAttribute('disabled')).toBe('');
});

// this seems like it might mask programmer error, but it's existing behavior.
itRenders('boolean prop with zero value', async render => {
const e = await render(<div hidden={0} />);
expect(e.getAttribute('hidden')).toBe(null);
const e = await render(<div disabled={0} />);
expect(e.getAttribute('disabled')).toBe(null);
});

itRenders('no boolean prop with null value', async render => {
const e = await render(<div hidden={null} />);
expect(e.hasAttribute('hidden')).toBe(false);
const e = await render(<div disabled={null} />);
expect(e.hasAttribute('disabled')).toBe(false);
});

itRenders('no boolean prop with function value', async render => {
const e = await render(<div hidden={function () {}} />, 1);
expect(e.hasAttribute('hidden')).toBe(false);
const e = await render(<div disabled={function () {}} />, 1);
expect(e.hasAttribute('disabled')).toBe(false);
});

itRenders('no boolean prop with symbol value', async render => {
const e = await render(<div hidden={Symbol('foo')} />, 1);
expect(e.hasAttribute('hidden')).toBe(false);
const e = await render(<div disabled={Symbol('foo')} />, 1);
expect(e.hasAttribute('disabled')).toBe(false);
});
});

Expand Down

0 comments on commit 8f5e56c

Please sign in to comment.