-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#24 added tests and prop types for Textarea component
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
src/components/ui-elements/textarea/__snapshots__/textarea.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`rendering testing renders without error 1`] = `"<div class=\\"form-group bmd-form-group\\"><label class=\\"control-label bmd-label-static\\" for=\\"the-textarea\\">the textarea</label><textarea name=\\"the-textarea\\" id=\\"the-textarea\\" data-test=\\"textarea-node\\" rows=\\"1\\" class=\\"form-control\\">Some big text</textarea></div>"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
|
||
import Textarea from './textarea' | ||
import { node } from 'prop-types' | ||
|
||
const mockUseEffect = jest.fn() | ||
React.useEffect = mockUseEffect | ||
|
||
const setup = (props) => { | ||
mockUseEffect.mockClear() | ||
|
||
const defaultProps = { input: { name: 'the-textarea', value: 'Some big text', onChange: () => { } }, label: 'the textarea' } | ||
return mount(<Textarea {...defaultProps} {...props} />) | ||
} | ||
|
||
describe('rendering testing', () => { | ||
test('renders without error', () => { | ||
const wrapper = setup() | ||
expect(wrapper.html()).toMatchSnapshot() | ||
}) | ||
|
||
test('counts height on value change', () => { | ||
const currentProps = { input: { name: 'the-name', value: 'The value' } } | ||
const wrapper = setup(currentProps) | ||
mockUseEffect.mockClear() | ||
wrapper.setProps({ input: { name: 'the-name', value: 'The other value' } }) | ||
expect(mockUseEffect).toHaveBeenCalled() | ||
}) | ||
|
||
test('does not count height on other prop change (except for value)', () => { | ||
const wrapper = setup() | ||
mockUseEffect.mockClear() | ||
wrapper.update() | ||
expect(mockUseEffect).not.toHaveBeenCalled() | ||
}) | ||
|
||
test('renders the value got from props on mount', () => { | ||
const nodeValue = 'Some saved text' | ||
const wrapper = setup({ input: { value: nodeValue } }) | ||
console.log(wrapper.debug()) | ||
const textareaNode = wrapper.find('[data-test="textarea-node"]') | ||
expect(textareaNode.prop('value')).toEqual(nodeValue) | ||
}) | ||
}) |