Skip to content

Commit 8e555ef

Browse files
committed
fix tests and rollup
1 parent 85ce773 commit 8e555ef

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`not applying the ref prop results in an error 1`] = `downshift: The ref prop "ref" from getMenuProps was not applied correctly on your menu element.`;
4-
5-
exports[`using a composite component and calling getMenuProps without a refKey results in an error 1`] = `downshift: The ref prop "ref" from getMenuProps was not applied correctly on your menu element.`;

src/__tests__/downshift.get-button-props.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,7 @@ test('getToggleButtonProps returns all given props', () => {
7474
const Button = jest.fn(props => <button {...props} />)
7575
setup({buttonProps, Button})
7676
expect(Button).toHaveBeenCalledTimes(1)
77-
const context = expect.any(Object)
78-
expect(Button).toHaveBeenCalledWith(
79-
expect.objectContaining(buttonProps),
80-
context,
81-
)
77+
expect(Button).toHaveBeenCalledWith(expect.objectContaining(buttonProps), undefined)
8278
})
8379

8480
// normally this test would be like the others where we render and then simulate a click on the

src/__tests__/downshift.get-menu-props.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ afterEach(() => console.error.mockRestore())
88
const Menu = ({innerRef, ...rest}) => <div ref={innerRef} {...rest} />
99
const RefMenu = React.forwardRef((props, ref) => <div ref={ref} {...props} />)
1010

11-
test('using a composite component and calling getMenuProps without a refKey results in an error', () => {
11+
test('using a composite component and calling getMenuProps without a refKey does not result in error anymore', () => {
1212
const MyComponent = () => (
1313
<Downshift
1414
children={({getMenuProps}) => (
@@ -19,7 +19,7 @@ test('using a composite component and calling getMenuProps without a refKey resu
1919
/>
2020
)
2121
render(<MyComponent />)
22-
expect(console.error.mock.calls[1][0]).toMatchSnapshot()
22+
expect(console.error).not.toHaveBeenCalled()
2323
})
2424

2525
test('not applying the ref prop results in an error', () => {

src/__tests__/downshift.misc.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// but we still want to have tested.
33

44
import * as React from 'react'
5-
import * as ReactDOM from 'react-dom'
5+
import * as ReactDOM from 'react-dom/client'
66
import {act, render} from '@testing-library/react'
77
import Downshift from '../'
88

@@ -68,21 +68,38 @@ test('toggleMenu can take no arguments at all', () => {
6868
)
6969
})
7070

71-
test('clearItems clears the all items', () => {
71+
test('clearItems clears all items', () => {
7272
const item = 'Chess'
73+
7374
const children = ({getItemProps}) => (
7475
<div>
7576
<div key={item} {...getItemProps({item})}>
7677
{item}
7778
</div>
7879
</div>
7980
)
80-
// IMPLEMENTATION DETAIL TEST :-(
81-
// eslint-disable-next-line react/no-render-return-value
82-
const downshiftInstance = ReactDOM.render(
83-
<Downshift>{children}</Downshift>,
84-
document.createElement('div'),
85-
)
81+
82+
// Wrap Downshift to expose its instance methods through a ref
83+
const DownshiftWrapper = React.forwardRef((_props, ref) => {
84+
const innerRef = React.useRef(null)
85+
86+
React.useImperativeHandle(ref, () => innerRef.current)
87+
88+
return <Downshift ref={innerRef}>{children}</Downshift>
89+
})
90+
91+
const container = document.createElement('div')
92+
const root = ReactDOM.createRoot(container)
93+
94+
const dsRef = React.createRef()
95+
96+
// eslint-disable-next-line testing-library/no-unnecessary-act
97+
act(() => {
98+
root.render(<DownshiftWrapper ref={dsRef} />)
99+
})
100+
101+
const downshiftInstance = dsRef.current
102+
86103
expect(downshiftInstance.items).toEqual([item])
87104
downshiftInstance.clearItems()
88105
expect(downshiftInstance.items).toEqual([])

tsconfig.preact.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "preact/dist"
5+
}
6+
}

0 commit comments

Comments
 (0)