|
1 | 1 | import { shallowMount, mount } from '@vue/test-utils' |
2 | 2 | import Input from '../../src/components/input/Input.vue' |
3 | 3 |
|
| 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 | + |
4 | 15 | describe('Input.vue', () => { |
5 | 16 | it('is rendered as input', () => { |
6 | 17 | const wrapper = shallowMount(Input, { |
@@ -28,12 +39,29 @@ describe('Input.vue', () => { |
28 | 39 | wrapper.setProps({ type: 'textarea' }) |
29 | 40 | expect(wrapper.find('textarea').exists()).toBe(true) |
30 | 41 | }) |
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', () => { |
32 | 56 | 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) |
37 | 65 | }) |
38 | 66 | it('is disabled ', () => { |
39 | 67 | const wrapper = shallowMount(Input) |
|
0 commit comments