-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(FormGroup): fields properly inherit flags
- Loading branch information
1 parent
33c089f
commit 8cf8d11
Showing
2 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
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,78 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { defineComponent, h } from 'vue'; | ||
|
||
import textFieldMixin from '../components/mixins/textFieldMixin'; | ||
|
||
import CFormGroup from '../components/CFormGroup/CFormGroup'; | ||
|
||
import useFormGroup from './useFormGroup'; | ||
|
||
const ComponentWithinFormGroup = defineComponent({ | ||
mixins: [textFieldMixin], | ||
|
||
setup(props) { | ||
return { | ||
formGroup: useFormGroup(props, ['required', 'disabled', 'readonly']), | ||
}; | ||
}, | ||
|
||
render() { | ||
return h('input'); | ||
}, | ||
}); | ||
|
||
describe('useFormGroup', () => { | ||
let wrapper = null; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(CFormGroup, { | ||
props: { | ||
required: false, | ||
disabled: false, | ||
readonly: false, | ||
}, | ||
slots: { | ||
default: () => h(ComponentWithinFormGroup), | ||
}, | ||
}); | ||
}); | ||
|
||
it('exposes the form group', () => { | ||
expect( | ||
wrapper.findComponent(ComponentWithinFormGroup).vm.formGroup | ||
).toMatchObject({ | ||
flags: { | ||
required: false, | ||
disabled: false, | ||
readonly: false, | ||
}, | ||
formGroup: { | ||
// Exact value is not important, just that it's an object | ||
}, | ||
}); | ||
}); | ||
|
||
it('has reactive flags', async () => { | ||
expect( | ||
wrapper.findComponent(ComponentWithinFormGroup).vm.formGroup.flags | ||
).toMatchObject({ | ||
required: false, | ||
disabled: false, | ||
readonly: false, | ||
}); | ||
|
||
await wrapper.setProps({ | ||
required: true, | ||
disabled: true, | ||
readonly: true, | ||
}); | ||
|
||
expect( | ||
wrapper.findComponent(ComponentWithinFormGroup).vm.formGroup.flags | ||
).toStrictEqual({ | ||
required: true, | ||
disabled: true, | ||
readonly: true, | ||
}); | ||
}); | ||
}); |
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