我想使用jest + zyme测试appHook.jsx
文件中存在的功能。请提供用于为此文件编写测试用例的流程。
appHook.jsx
import { useContext } from 'react';
import { AppContext } from '../context/appContext';
const AppHook = () => {
const [state, setState] = useContext(AppContext);
function updateColors(colors) {
setState(state => ({ ...state, customerSpecificColor: colors }));
}
function setDisplayCommonLoader(isDisplay) {
setState(state => ({ ...state, displayCommonLoader: isDisplay }));
}
return {
updateColors,
customerSpecificColor: state.customerSpecificColor,
setDisplayCommonLoader,
displayCommonLoader: state.displayCommonLoader,
};
};
export default AppHook;
appContext.jsx
import React, { useState } from 'react';
const AppContext = React.createContext([{}, () => {}]);
const AppProvider = props => {
const [state, setState] = useState({
customerSpecificColor: 'blue',
displayCommonLoader: false
});
return (
<AppContext.Provider value={[state, setState]}>
{props.children}
</AppContext.Provider>
);
};
export { AppContext, AppProvider };