Skip to content

Commit

Permalink
Merge pull request #158 from mmarkelov/Add_tests
Browse files Browse the repository at this point in the history
Add some tests
  • Loading branch information
glennreyes authored Aug 2, 2019
2 parents 976cdab + e5a3b47 commit 14cd5f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/__tests__/CountUp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ it('renders with delay as a render prop component correctly', () => {
expect(container).toMatchSnapshot();
});

it('renders with delay as a render prop component correctly', () => {
console.error = jest.fn();

const { container } = render(
<CountUp delay={1} end={10}>
{({ countUpRef }) => <rect ref={countUpRef} />}
</CountUp>,
);

expect(console.error).toHaveBeenCalled();
});

it('renders as a render prop component correctly', () => {
const { container } = render(
<CountUp end={10}>{({ countUpRef }) => <div ref={countUpRef} />}</CountUp>,
Expand Down
20 changes: 10 additions & 10 deletions src/__tests__/useCountUp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,34 @@ it('calls update correctly with hook', () => {
const spy = {};

const Hook = () => {
const { countUp, update } = useCountUp({ end: 10 });
spy.update = update;
spyOn(spy, 'update');
return <span onClick={spy.update}>{countUp}</span>;
const onUpdate = jest.fn();
const { countUp, update } = useCountUp({ end: 10, onUpdate });
spy.onUpdate = onUpdate;
return <span onClick={update}>{countUp}</span>;
};

const { container } = render(<Hook />);
flushEffects();
jest.runAllTimers();
fireEvent.click(container.firstChild);
jest.runAllTimers();
expect(spy.update).toHaveBeenCalled();
expect(spy.onUpdate).toHaveBeenCalled();
});

it('calls pauseResume correctly with hook', () => {
const spy = {};

const Hook = () => {
const { countUp, pauseResume } = useCountUp({ end: 10 });
spy.pauseResume = pauseResume;
spyOn(spy, 'pauseResume');
return <span onClick={spy.pauseResume}>{countUp}</span>;
const onPauseResume = jest.fn();
const { countUp, pauseResume } = useCountUp({ end: 10, onPauseResume });
spy.onPauseResume = onPauseResume;
return <span onClick={pauseResume}>{countUp}</span>;
};

const { container } = render(<Hook />);
flushEffects();
jest.runAllTimers();
fireEvent.click(container.firstChild);
jest.runAllTimers();
expect(spy.pauseResume).toHaveBeenCalled();
expect(spy.onPauseResume).toHaveBeenCalled();
});

0 comments on commit 14cd5f6

Please sign in to comment.