React bileşenlerini test etmek için Enzyme
kullanıyorum. Ham bağlantısız bileşenin test edilmesi için bunu ihraç etmem ve test etmem gerektiğini anladım (bunu yaptım). Bağlı bileşen için bir test yazmayı başardım, ancak bu doğru yolun olup olmadığına ve ayrıca bağlı bileşen için tam olarak ne test etmek istediğime gerçekten emin değilim. Sizin de belirttiğiniz gibiRedux: Bağlı bir bileşen nasıl test edilir?
Container.jsx
import {connect} from 'react-redux';
import Login from './Login.jsx';
import * as loginActions from './login.actions';
const mapStateToProps = state => ({
auth: state.auth
});
const mapDispatchToProps = dispatch => ({
loginUser: credentials => dispatch(loginActions.loginUser(credentials))
});
export default connect(mapStateToProps, mapDispatchToProps)(Login);
Container.test.js
import React from 'react';
import {Provider} from 'react-redux';
import {mount, shallow} from 'enzyme';
import {expect} from 'chai';
import LoginContainer from '../../src/login/login.container';
import Login from '../../src/login/Login';
describe('Container Login',() => {
it('should render the container component',() => {
const storeFake = state => ({
default:() => {
},
subscribe:() => {
},
dispatch:() => {
},
getState:() => ({ ...state })
});
const store = storeFake({
auth: {
sport: 'BASKETBALL'
}
});
const wrapper = mount(
<Provider store={store}>
<LoginContainer />
</Provider>
);
expect(wrapper.find(LoginContainer).length).to.equal(1);
const container = wrapper.find(LoginContainer);
expect(container.find(Login).length).to.equal(1);
expect(container.find(Login).props().auth).to.eql({ sport: 'BASKETBALL' });
});
});
Bu, mapStateToProps ve mapDispatch için yeterli olur mu? – Umair
Evet gerçekten de .. Bir kapsama aracıyla kontrol etmeli u tamamen bilmek istiyorum fiili şey NE test etmek temelde – anoop
kaplıdır bulacaksınız biz konteyner/akıllı bileşeni test yapacağız? – Umair