รายละเอียดสำหรับเรียนรู้ React ปี 2020-2023 โดยโค้ชพล ดูหลักสูตรได้ที่ https://www.nextflow.in.th/react-training
เราจะมีการ import Spin component ของ Ant Design เข้ามาช่วยในที่นี้ด้วย
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { Spin } from "antd";
import Enzyme, { shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
Enzyme.configure({ adapter: new Adapter() })
describe('App component', () => {
it('renders without crashing', () => {
const component = shallow(<App />);
});
it('should contain <Spin>', () => {
const component = shallow(<App />);
expect(component.find('Spin')).toHaveLength(1);
});
})
ทดสอบรัน test
component.find()
สามารถใช้หา children component ที่อยู่ด้านใน App ได้ ซึ่งถ้าเจอจะนับเป็นจำนวนที่พบเริ่มจาก import เพิ่มเติมจาก Ant Design
import { Layout, Spin } from 'antd';
และครอบ Component ของเรา
function App() {
return (
<div>
<Spin>
<Layout className="layout">
<MenuBar />
<Switch>
//...
<Footer style=>React Redux Workshop ©2012-2019 Created by Nextflow.in.th</Footer>
</Layout>,
</Layout>
</Spin>
</div>
);
}
ทดสอบรัน test