Skip to content

Commit

Permalink
[enzyme-test-suites] Remove the describe in useContext test to pass c…
Browse files Browse the repository at this point in the history
…i under React v16.3
  • Loading branch information
chenesan committed Jun 11, 2019
1 parent d01bcfa commit aae8ad1
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions packages/enzyme-test-suite/test/shared/hooks/useContext.jsx
Expand Up @@ -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 (
<div>
{title}
</div>
);
};
const wrapper = Wrap(<UiComponent />);
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);

Expand All @@ -38,22 +55,13 @@ export default function describeUseContext({
<UiComponent />
</TitleContext.Provider>
);

it('render ui component with initial context value', () => {
const wrapper = Wrap(<UiComponent />);
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(<App />);
const subWrapper = isShallow ? wrapper.dive().dive() : wrapper;
expect(subWrapper.text()).to.equal(customTitle);
});
const wrapper = Wrap(<App />);
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);

Expand All @@ -80,7 +88,7 @@ export default function describeUseContext({
</div>
);

const App = () => {
const Parent = () => {
const [state, setState] = useState(initialState);

return (
Expand All @@ -92,27 +100,25 @@ export default function describeUseContext({
);
};

it('test render, get and set context value ', () => {
const wrapper = Wrap(<App />);

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(`<span className="grandChildState">
const wrapper = Wrap(<Parent />);

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(`<span className="grandChildState">
${String(initialState)}
</span>`);

getGrandChild().find('button').props().onClick();
wrapper.update();
expect(getGrandChild().find('.grandChildState').debug()).to.equal(`<span className="grandChildState">
getGrandChild().find('button').props().onClick();
wrapper.update();
expect(getGrandChild().find('.grandChildState').debug()).to.equal(`<span className="grandChildState">
${String(initialState + 1)}
</span>`);
});
});
});
}

0 comments on commit aae8ad1

Please sign in to comment.