Skip to content

Commit

Permalink
[tests] invoke: Add failed mount test without explicit act call
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan authored and ljharb committed Jun 9, 2019
1 parent dbb5aae commit 05d885c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/enzyme-test-suite/test/shared/methods/invoke.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import React from 'react';
import { expect } from 'chai';
import sinon from 'sinon-sandbox';
import {
itIf,
} from '../../_helpers';
import {
is,
} from '../../_helpers/version';

import {
useEffect,
useState,
} from '../../_helpers/react-compat';

export default function describeInvoke({
Wrap,
WrapperName,
isShallow,
}) {
describe('.invoke(propName)(..args)', () => {
class CounterButton extends React.Component {
Expand Down Expand Up @@ -84,5 +96,32 @@ export default function describeInvoke({
expect(arg1).to.equal(a);
expect(arg2).to.equal(b);
});

// TODO: enable when the shallow renderer fixes its bug
itIf(!isShallow && is('>= 16.8'), 'works without explicit `act` wrapper', () => {
function App() {
const [counter, setCounter] = useState(0);
const [result, setResult] = useState(0);
useEffect(
() => setResult(counter * 2),
[counter],
);
return (
<button type="button" onClick={() => setCounter(input => input + 1)}>{result}</button>
);
}
const wrapper = Wrap(<App />);

const expected = ['0', '2', '4', '6'];

const actual = [wrapper.find('button').text()]
.concat(Array.from({ length: 3 }, () => {
wrapper.find('button').invoke('onClick')();
wrapper.update();

return wrapper.find('button').text();
}));
expect(actual).to.eql(expected);
});
});
}

0 comments on commit 05d885c

Please sign in to comment.