รายละเอียดสำหรับเรียนรู้ React ปี 2020-2023 โดยโค้ชพล ดูหลักสูตรได้ที่ https://www.nextflow.in.th/react-training
สร้างไฟล์ src/redux/sagas/signin.saga.reducer.test.js
import { expectSaga } from 'redux-saga-test-plan';
import appReducer from "../app.reducer";
import watcher, { doSignIn } from "./signin.saga";
import actions from '../actions';
import { push } from 'connected-react-router';
describe('Sign In Saga Integration Test', () => {
it('worker SignIn Saga success', () => {
const authInfo = { username: 'a', password: 'pass' }
const payload = {
type: actions.ActionTypes.SIGN_IN_START,
payload: authInfo
}
return expectSaga(doSignIn, payload)
.withReducer(appReducer)
.hasFinalState({
loading: false
})
.run()
});
});
และทดสอบรัน test
it('worker SignIn Saga success effect home token', () => {
const authInfo = { username: 'a', password: 'pass' }
const payload = {
type: actions.ActionTypes.SIGN_IN_START,
payload: authInfo
}
return expectSaga(doSignIn, payload)
.withReducer(homepageReducer)
.run()
.then((result) => {
expect(result.storeState.token).toBeTruthy()
});
});
และทดสอบรัน test