Skip to content

Commit b5addd5

Browse files
committed
Add: Input spec for attrs
1 parent f2dce4f commit b5addd5

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

tests/unit/Input.spec.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { shallowMount, mount } from '@vue/test-utils'
22
import Input from '../../src/components/input/Input.vue'
33

4+
const defaultProps = {
5+
placeholder: 'text',
6+
autocomplete: true,
7+
name: 'text',
8+
disabled: true,
9+
readonly: true,
10+
min: 1,
11+
max: 1,
12+
rows: 1
13+
}
14+
415
describe('Input.vue', () => {
516
it('is rendered as input', () => {
617
const wrapper = shallowMount(Input, {
@@ -28,12 +39,29 @@ describe('Input.vue', () => {
2839
wrapper.setProps({ type: 'textarea' })
2940
expect(wrapper.find('textarea').exists()).toBe(true)
3041
})
31-
it('placeholder is rendered ', () => {
42+
it('input attributes is rendered', () => {
43+
const wrapper = shallowMount(Input)
44+
wrapper.setProps(defaultProps)
45+
const attrs = wrapper.find('input').attributes()
46+
expect(attrs.type).toContain('text')
47+
expect(attrs.autocomplete).toContain('off')
48+
expect(attrs.placeholder).toContain('text')
49+
expect(attrs.name).toContain('text')
50+
expect(attrs.disabled).toContain('disabled')
51+
expect(attrs.readonly).toContain('readonly')
52+
expect(attrs.min).toContain(1)
53+
expect(attrs.max).toContain(1)
54+
})
55+
it('textarea attributes is rendered', () => {
3256
const wrapper = shallowMount(Input)
33-
wrapper.setProps({ placeholder: 'text' })
34-
const placeholderAttr = wrapper.find('input').attributes().placeholder
35-
expect(wrapper.props().placeholder).toBe('text')
36-
expect(placeholderAttr).toContain('text')
57+
wrapper.setProps({ ...defaultProps, type: 'textarea' })
58+
const attrs = wrapper.find('textarea').attributes()
59+
expect(attrs.type).toContain('textarea')
60+
expect(attrs.placeholder).toContain('text')
61+
expect(attrs.name).toContain('text')
62+
expect(attrs.disabled).toContain('disabled')
63+
expect(attrs.readonly).toContain('readonly')
64+
expect(attrs.rows).toContain(1)
3765
})
3866
it('is disabled ', () => {
3967
const wrapper = shallowMount(Input)

0 commit comments

Comments
 (0)