Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NMinhNguyen committed Apr 6, 2020
1 parent 1125fc1 commit 33a18f8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/material-ui/src/utils/useId.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { createClientRender } from 'test/utils/createClientRender';
import useId from './useId';

const TestComponent = ({ id: idProp }) => {
const id = useId(idProp);
return <span>{id}</span>;
};

TestComponent.propTypes = {
id: PropTypes.string,
};

describe('useId', () => {
const render = createClientRender();

it('returns the provided ID', () => {
const { getByText } = render(<TestComponent id="some-id" />);

expect(getByText('some-id')).to.not.be.null;
});

it("generates an ID if one isn't provided", () => {
const { getByText } = render(<TestComponent />);

expect(getByText(/^mui-[0-9]+$/)).to.not.be.null;
});
});

0 comments on commit 33a18f8

Please sign in to comment.