Skip to content

Instantly share code, notes, and snippets.

View echo304's full-sized avatar

Sangboak Lee echo304

  • Coquitlam, Canada
  • 15:54 (UTC -07:00)
  • LinkedIn in/echo304
View GitHub Profile
# With in Expression inside guard clause
case result do
result when result in [:ok, true, 1] -> :ok
_ -> :error
end
# Without in Expression
case result do
:ok -> :ok
true -> :ok
class ComponentToBeTested extends Component {
// 생략
multiply(data) {
return data * 10;
}
square(data) {
return Math.pow(data, 3); // 의도된 실수
}
it('should render <ChildComponent />', () => {
const wrapper = shallow(<ComponentToBeTested />);
expect(wrapper.find('ChildComponent').length).toEqual(1);
});
it('should pass a number multiplied by 10 as data prop', () => {
const wrapper = shallow(<ComponentToBeTested data={2}/>);
expect(wrapper.find('ChildComponent').prop('data')).toEqual(20);
});
class ComponentToBeTested extends Component {
constructor(props) {
super(props);
this.state = {
isActive: false
};
this.handleButtonClick = this.handleButtonClick.bind(this);
}
handleButtonClick() {
class ComponentToBeTested extends Component {
constructor(props) {
super(props);
this.state = {
isActive: false,
};
this.handleButtonClick = this.handleButtonClick.bind(this);
}
handleButtonClick() {
@echo304
echo304 / spec_3.js
Last active November 21, 2017 00:00
it('should render button.test-button', () => {
const wrapper = shallow(<ComponentToBeTested />);
expect(wrapper.find('button.test-button').length).toEqual(1);
});
it('should render text \'FOO\' inside button.test-button', () => {
const wrapper = shallow(<ComponentToBeTested />);
expect(wrapper.find('button.test-button').text()).toEqual('FOO');
});
class ComponentToBeTested extends Component {
constructor(props) {
super(props);
this.state = {
isActive: false,
};
}
// 생략
}
it('should have isActive state\(default: false\)', () => {
const wrapper = shallow(<ComponentToBeTested />);
expect(wrapper.state('isActive')).toEqual(false);
});
import React, { Component } from 'react';
class ComponentToBeTested extends Component {
render() {
return (
<div className="ComponentToBeTested" />
);
}
}
@echo304
echo304 / spec_1.js
Last active November 20, 2017 08:10
import React from 'react';
import { shallow } from 'enzyme';
import ComponentToBeTested from './ComponentToBeTested';
it('renders without crashing', () => {
shallow(<ComponentToBeTested />);
});