Skip to content

Commit a593da7

Browse files
committed
fix compose order & add tests
1 parent 7ac093b commit a593da7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/utils/compose.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import * as React from 'react'
22
import renderProps from './renderProps'
33

44
const isElement = element => typeof element.type === 'function'
5-
const name = element =>
6-
(isElement(element) ? element.type.name : element.name).toLowerCase()
75

86
const compose = (...elements) => {
97
return composedProps => {
@@ -31,7 +29,7 @@ const compose = (...elements) => {
3129
return elementFn(element, {}, renderFn)
3230
}
3331

34-
return stackProps(elements.length - 1, elements)
32+
return stackProps(elements.length - 1, elements.reverse())
3533
}
3634
}
3735

tests/components/Compose.test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@ import TestRenderer from 'react-test-renderer'
33
import { Compose, Counter, Toggle } from '../../src'
44

55
test('<Compose />', () => {
6-
const renderFn = jest.fn().mockReturnValue(null)
6+
let lastCallProps = null
7+
const renderFn = (...props) => {
8+
lastCallProps = props
9+
return null
10+
}
11+
712
TestRenderer.create(<Compose states={[Counter, Toggle]} render={renderFn} />)
8-
// TODO
13+
14+
expect(lastCallProps[0].count).toBe(0)
15+
expect(lastCallProps[1].on).toBe(false)
16+
17+
lastCallProps[0].inc()
18+
lastCallProps[0].incBy(3)
19+
lastCallProps[1].toggle()
20+
21+
expect(lastCallProps[0].count).toBe(4)
22+
expect(lastCallProps[1].on).toBe(true)
923
})

0 commit comments

Comments
 (0)