Skip to content

Commit

Permalink
More tetst added.
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaals committed Aug 27, 2019
1 parent 89cd688 commit 0909c4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/components/button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import ReactDOM from 'react-dom';
import Button from './Button';
import ReactDOM from 'react-dom'
import Button from './Button'
import { render, fireEvent, waitForElement, waitForDomChange } from '@testing-library/react'

describe('Button component', () => {
it('renders without crashing', () => {
Expand All @@ -9,3 +10,16 @@ describe('Button component', () => {
ReactDOM.unmountComponentAtNode(div);
});
})

describe('Dom updates', () => {
it('should update button label to "Hello 2"', async (done) => {
const {getByTestId} = render(<Button interval={500}/>)
const el = await waitForElement(() => getByTestId('btn')) as HTMLButtonElement
fireEvent.click(el)
fireEvent.click(el)
fireEvent.click(el)
const t = await waitForDomChange({container: el})
expect(el.textContent).toEqual('Hello 2')
done()
})
})
4 changes: 3 additions & 1 deletion src/components/button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { SFC} from 'react'
import {useClick} from './useClick'

type Props = {
interval?: number;
label?:string;
}

const Button:SFC<Props> = (props:Props) => {
return <button data-testid="btn">Hello</button>
const {ref, count} = useClick(props.interval)
return <button data-testid="btn" ref={ref}>Hello {count}</button>
}

export default Button

0 comments on commit 0909c4d

Please sign in to comment.