Skip to content

Instantly share code, notes, and snippets.

@Mindaugas-Jacionis
Created August 16, 2017 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mindaugas-Jacionis/21e9d8638254887befbd31ddbcee80a6 to your computer and use it in GitHub Desktop.
Save Mindaugas-Jacionis/21e9d8638254887befbd31ddbcee80a6 to your computer and use it in GitHub Desktop.
Tests
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class Button extends Component {
static propTypes = {
type: PropTypes.string,
text: PropTypes.string,
onClick: PropTypes.func
};
static defaultProps = {
type: 'button',
text: 'Submit',
onClick: () => {}
};
onClick() {
const { onClick } = this.props;
onClick();
}
render() {
const { type, text } = this.props;
return (
<button
type={type}
onClick={() => this.onClick()}
className={'button'}
>
{text}
</button>
);
}
}
export default Button;
import React from 'react';
import { Button } from '../components/ui';
import { shallow, mount, render } from 'enzyme';
/* Testing props of components */
describe('Input component prop tests', () => {
it('should render a document title', done => {
const wrapper = shallow(
<Button text={'Test'} type={'submit'} />
);
expect(wrapper.props().type).toEqual('submit'); // passes
expect(wrapper.props().text).toEqual('Test'); // does not pass
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment