|
1 | 1 | import * as React from 'react' |
2 | 2 | import TestRenderer from 'react-test-renderer' |
3 | 3 | import { Compose, Counter, Toggle } from '../../src' |
| 4 | +import { lastCallArgs } from './utils' |
4 | 5 |
|
5 | 6 | test('<Compose />', () => { |
6 | | - let lastCallProps = null |
7 | | - const renderFn = (...props) => { |
8 | | - lastCallProps = props |
9 | | - return null |
10 | | - } |
| 7 | + const renderFn = jest.fn().mockReturnValue(null) |
11 | 8 |
|
12 | 9 | TestRenderer.create( |
13 | 10 | <Compose components={[Counter, Toggle]} render={renderFn} /> |
14 | 11 | ) |
15 | 12 |
|
16 | | - expect(lastCallProps[0].count).toBe(0) |
17 | | - expect(lastCallProps[1].on).toBe(false) |
| 13 | + expect(renderFn).toBeCalledTimes(1) |
| 14 | + expect(renderFn).lastCalledWith( |
| 15 | + expect.objectContaining({ count: 0 }), |
| 16 | + expect.objectContaining({ on: false }) |
| 17 | + ) |
18 | 18 |
|
19 | | - lastCallProps[0].inc() |
20 | | - lastCallProps[0].incBy(3) |
21 | | - lastCallProps[1].toggle() |
| 19 | + lastCallArgs(renderFn)[0].inc() |
| 20 | + lastCallArgs(renderFn)[0].incBy(3) |
| 21 | + lastCallArgs(renderFn)[1].toggle() |
22 | 22 |
|
23 | | - expect(lastCallProps[0].count).toBe(4) |
24 | | - expect(lastCallProps[1].on).toBe(true) |
| 23 | + expect(renderFn).toBeCalledTimes(4) |
| 24 | + expect(renderFn).lastCalledWith( |
| 25 | + expect.objectContaining({ count: 4 }), |
| 26 | + expect.objectContaining({ on: true }) |
| 27 | + ) |
25 | 28 | }) |
0 commit comments