Skip to content

Instantly share code, notes, and snippets.

View echo304's full-sized avatar

Sangboak Lee echo304

  • Coquitlam, Canada
  • 02:46 (UTC -07:00)
  • LinkedIn in/echo304
View GitHub Profile
class ComponentToBeTested extends React.Component {
constructor(props) {
super(props);
this.state = {
isActive: false
};
this.handleButtonClick = this.handleButtonClick.bind(this);
}
handleButtonClick() {
Foo.propTypes = {
customProp: function(props, propName, componentName) {
if (!/matchme/.test(props[propName])) {
return new Error(
'Invalid prop `' + propName + '` supplied to' +
' `' + componentName + '`. Validation failed.'
);
}
}
};
Chart.propTypes = {
config: PropTypes.shape({
series: PropTypes.array.isRequired,
xAxis: PropTypes.shape({
categories: PropTypes.array,
}),
}).isRequired,
chartType: PropTypes.arrayOf(PropTypes.string).isRequired,
currentChartType: PropTypes.oneOf(['view', 'conversion']),
};
Chart.propTypes = {
config: PropTypes.object.isRequired,
chartType: PropTypes.array.isRequired,
currentChartType: PropTypes.string,
};
describe('<Foo />', () => {
describe('#componentDidMount', () => {
it('should return foo', () => {
const cb = sinon.spy();
mount(<Foo callback={cb} />);
expect(cb.calledOnce).to.be.eq(true);
});
});
});
class Foo extends React.Component {
componentDidMount() {
this.props.callback();
}
/* ... */
render() { /* ... */ }
}
/* ... */
class Foo extends React.Component {
state = { test: 'test' }
/* ... */
test() {
return this.state.test;
}
/* ... */
class Foo extends React.Component {
/* ... */
test() {
return 'foo';
}
/* ... */
class Foo extends React.Component {
/* ... */
test() {
return 'foo';
}