From aae8ad155978fdcae4c94072f47b5a2690148377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E4=B9=99=E5=B1=B1?= Date: Tue, 11 Jun 2019 13:58:11 +0800 Subject: [PATCH] [enzyme-test-suites] Remove the describe in useContext test to pass ci under React v16.3 --- .../test/shared/hooks/useContext.jsx | 68 ++++++++++--------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/packages/enzyme-test-suite/test/shared/hooks/useContext.jsx b/packages/enzyme-test-suite/test/shared/hooks/useContext.jsx index 14b41001f..1bf4ea229 100644 --- a/packages/enzyme-test-suite/test/shared/hooks/useContext.jsx +++ b/packages/enzyme-test-suite/test/shared/hooks/useContext.jsx @@ -18,7 +18,24 @@ export default function describeUseContext({ isShallow, }) { describeIf(hasHooks, 'hooks: useContext', () => { - describe('simple example', () => { + it('render ui component with initial context value', () => { + const initialTitle = 'initialTitle'; + const TitleContext = createContext(initialTitle); + + const UiComponent = () => { + const title = useContext(TitleContext); + return ( +
+ {title} +
+ ); + }; + const wrapper = Wrap(); + expect(wrapper.text()).to.equal(initialTitle); + }); + + // TODO: useContext: enable when shallow dive supports createContext + itIf(!isShallow, 'render ui component with value from outer provider', () => { const initialTitle = 'initialTitle'; const TitleContext = createContext(initialTitle); @@ -38,22 +55,13 @@ export default function describeUseContext({ ); - - it('render ui component with initial context value', () => { - const wrapper = Wrap(); - expect(wrapper.text()).to.equal(initialTitle); - }); - - // TODO: useContext: enable when shallow dive supports createContext - itIf(!isShallow, 'render ui component with value from outer provider', () => { - const wrapper = Wrap(); - const subWrapper = isShallow ? wrapper.dive().dive() : wrapper; - expect(subWrapper.text()).to.equal(customTitle); - }); + const wrapper = Wrap(); + const subWrapper = isShallow ? wrapper.dive().dive() : wrapper; + expect(subWrapper.text()).to.equal(customTitle); }); // TODO: useContext: enable when shallow dive supports createContext - describeIf(!isShallow, 'useContext: with Setting', () => { + itIf(!isShallow, 'useContext: test render, get and set context value', () => { const initialState = 10; const context = createContext(null); @@ -80,7 +88,7 @@ export default function describeUseContext({ ); - const App = () => { + const Parent = () => { const [state, setState] = useState(initialState); return ( @@ -92,27 +100,25 @@ export default function describeUseContext({ ); }; - it('test render, get and set context value ', () => { - const wrapper = Wrap(); - - function getChild() { - const child = wrapper.find(MyChild); - return isShallow ? child.dive() : child; - } - function getGrandChild() { - const grandchild = getChild().find(MyGrandChild); - return isShallow ? grandchild.dive() : grandchild; - } - expect(getGrandChild().find('.grandChildState').debug()).to.equal(` + const wrapper = Wrap(); + + function getChild() { + const child = wrapper.find(MyChild); + return isShallow ? child.dive() : child; + } + function getGrandChild() { + const grandchild = getChild().find(MyGrandChild); + return isShallow ? grandchild.dive() : grandchild; + } + expect(getGrandChild().find('.grandChildState').debug()).to.equal(` ${String(initialState)} `); - getGrandChild().find('button').props().onClick(); - wrapper.update(); - expect(getGrandChild().find('.grandChildState').debug()).to.equal(` + getGrandChild().find('button').props().onClick(); + wrapper.update(); + expect(getGrandChild().find('.grandChildState').debug()).to.equal(` ${String(initialState + 1)} `); - }); }); }); }