我是测试新手 有一个鹰,它有一个组件和可以访问它的组作为输入。从商店获取用户可用的组列表,并返回一个组件或null
import { useSelector } from 'react-redux'
import accessCheck from './accessCheck'
const RequireAccess = ({ Component, accesses }) => {
const userGroups = useSelector((state) => state.currentUser.userData.groups)
if (accessCheck(accesses, userGroups)) {
return Component
}
return null
}
export default RequireAccess
我该如何测试? 我尝试了类似的方法,但显然是胡说八道
const initialState = {
currentUser: {
userData: {
groups: ['cmgui', 'cmgui-settings'],
},
},
}
const ReduxProvider = ({ children, reduxStore }) => (
<Provider store={reduxStore}>{children}</Provider>
)
const mockStore = configureStore()
let store
beforeEach(() => {
store = mockStore(initialState)
})
test('should render component', () => {
const SomeComponent = jest.fn()
const accesses = ['cm1gui']
const wrapper = shallow(
<ReduxProvider reduxStore={store}>
<RequireAccess
Component={SomeComponent}
accesses={accesses}
/>
</ReduxProvider>
)
console.log(wrapper.debug())
})