Skip to content

Commit

Permalink
[Box] migrate to testing library
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosvega91 committed Apr 24, 2020
1 parent 2231349 commit 4ed0066
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/material-ui/src/Box/Box.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import { assert } from 'chai';
import { expect } from 'chai';
import { createClientRender } from 'test/utils/createClientRender';
import { createMount } from '@material-ui/core/test-utils';
import describeConformance from '@material-ui/core/test-utils/describeConformance';
import Box from './Box';

describe('<Box />', () => {
let mount;

const render = createClientRender();
before(() => {
mount = createMount({ strict: true });
});
Expand All @@ -21,22 +22,25 @@ describe('<Box />', () => {
refInstanceof: window.HTMLDivElement,
}));

const testChildren = <div className="unique">Hello World</div>;
const testChildren = (
<div data-testid="child" className="unique">
Hello World
</div>
);

it('renders children and box content', () => {
const wrapper = mount(
const { container, getByTestId } = render(
<Box component="span" m={1}>
{testChildren}
</Box>,
);

assert.strictEqual(wrapper.contains(testChildren), true);
assert.strictEqual(wrapper.find('span').length, 1);
expect(container.firstChild).contain(getByTestId('child'));
expect(container.querySelectorAll('span').length).to.equal(1);
});

it('does not forward style props as DOM attributes', () => {
const elementRef = React.createRef();
mount(
render(
<Box
color="primary.main"
fontFamily="Comic Sans"
Expand All @@ -46,8 +50,8 @@ describe('<Box />', () => {
);

const { current: element } = elementRef;
assert.strictEqual(element.getAttribute('color'), null);
assert.strictEqual(element.getAttribute('font-family'), null);
assert.strictEqual(element.getAttribute('font-size'), null);
expect(element.getAttribute('color')).to.equal(null);
expect(element.getAttribute('font-family')).to.equal(null);
expect(element.getAttribute('font-size')).to.equal(null);
});
});

0 comments on commit 4ed0066

Please sign in to comment.