-
Notifications
You must be signed in to change notification settings - Fork 27
(Jest, Enzyme) 컴포넌트 단위, 통합 테스트
Sungdong Jo edited this page Nov 18, 2019
·
4 revisions
import { doIncrement, doDecrement } from './App';
describe('Local State', () => {
it('should increment the counter in state', () => {
const state = { counter: 0 };
const newState = doIncrement(state);
expect(newState.counter).to.equal(1);
});
it('should decrement the counter in state', () => {
const state = { counter: 0 };
const newState = doDecrement(state);
expect(newState.counter).to.equal(-1);
});
});
describe('App Component', () => {
it('Counter 래퍼를 그려낸다', () => {
const wrapper = shallow(<App />);
expect(wrapper.find(Counter)).to.have.length(1);
});
it('Counter 래퍼에 모든 Prop이 전달되었다', () => {
const wrapper = shallow(<App />);
let counterWrapper = wrapper.find(Counter);
expect(counterWrapper.props().counter).to.equal(0);
wrapper.setState({ counter: -1 });
counterWrapper = wrapper.find(Counter);
expect(counterWrapper.props().counter).to.equal(-1);
});
});
// Profile Component에 대한 테스트
// Profile.tsx
import React from 'react';
interface Props {
username: string;
name: string;
}
const Profile: React.FC<Props> = ({ username, name }: Props) => {
return (
<div>
<b>{username}!</b>
<span>({name})</span>
</div>
);
};
export default Profile;
// Profile.spec.tsx
describe('<Profile />', () => {
it('matches snapshot', () => {
const wrapper = mount(<Profile username="Sungdong Jo" name="Doong" />);
expect(wrapper).toMatchSnapshot();
});
it('renders username and name', () => {
const wrapper = mount(<Profile username="Sungdong Jo" name="Doong" />);
expect(wrapper.props().username).toBe('Sungdong Jo');
expect(wrapper.props().name).toBe('Doong');
const boldElement = wrapper.find('b');
expect(boldElement.contains('Sungdong Jo')).toBe(true);
const spanElement = wrapper.find('span');
expect(spanElement.text()).toBe('(Doong)');
});
});
실용적인 리액트 테스트 전략
DevOps
Infra Structure
컴포넌트 작성법
Client Sturcture
데이터베이스 스키마
Yarn workspace 명령어
Docker를 이용한 서버 개발 환경
Linting Tools