Skip to content

Latest commit

 

History

History
50 lines (31 loc) · 1.08 KB

18-1-prepare-first-test.md

File metadata and controls

50 lines (31 loc) · 1.08 KB

19. เตรียมเขียน Test UI ตัวแรก

1. สร้าง global test file

สร้างไฟล์ src/setupTests.js

import Enzyme, { shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({ adapter: new Adapter() }) 

2. เราจะทำการ import และตั้งค่า Enzyme module

// src/App.test.js

mport ReactDOM from 'react-dom';
import App from './App';

import Enzyme, { shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({ adapter: new Adapter() });

3. จากนั้น ก็สร้าง test case แรกของเรา

โดยส่วนแรก เราจะทดสอบว่า App component พังหรือไม่

// src/App.test.js

describe('App component', () => {
  
  it('renders without crashing', () => {
 
    const component = shallow(<App />);
  
  });
})

จากนั้นให้ทดสอบรัน test โดยใช้คำสั่ง

yarn test