반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 맥
- centos
- qunit
- linux
- 티스토리챌린지
- ReactNative
- 개발
- node
- jest
- build
- PYTHON
- 네트워크
- 리눅스
- TensorFlow
- react
- unittest
- localserver
- 오블완
- webpack
- IOS
- Android
- MAC
- 센토스
- VirtualBox
- MachineLearning
- Chrome
- xcode
- androidstudio
- vsCode
Archives
- Today
- Total
로메오의 블로그
[React Native] Jest Snapshot Testing 본문
반응형
화면 코딩하기
/App.js
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
} from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={{fontSize: 34}}>Hello</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});
Build 하기
$ react-native run-android
Test Code 작성
/__test__/App-test.js
import 'react-native';
import React from 'react';
import App from '../App';
import renderer from 'react-test-renderer';
test('App Snapshot', () => {
const snap = renderer.create(
<App />
).toJSON()
expect(snap).toMatchSnapshot()
});
Test 실행하기
$ npm test

snapshot을 실행하면 /__test__/__snapshot__/App-test.js.snap 파일이 json으로 생성됩니다.

화면 수정하기

fontSize를 34에서 24로 수정 후 Build하고 다시 test 코드를 실행합니다.
$ react-native run-android
$ npm test

저장된 /__test__/__snapshot__/App-test.js.snap에 저장된 snapshot과 다른부분이 있으면 오류가 발생합니다.
Snapshot 업데이트 하기
저장된 App-test.js.snap 파일을 업데이트 합니다.
$ npm test -- -u

반응형
'App & OS > Hybrid' 카테고리의 다른 글
[React Native] Jest - Element 정의 테스트 (2) | 2019.06.17 |
---|---|
[React Native] Jest - state 테스트 (0) | 2019.06.17 |
[React Native] Jest - function 테스트 (0) | 2019.06.17 |
[React Native] Plugin 설치/삭제하기 (0) | 2019.06.14 |
[React Native] 프로젝트 생성하기 (2019년 기준) (0) | 2019.06.14 |