-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(NcInputField): Support numeric values - if numeric also emit numeric
If the type is set to number and a number is passed as value also emit a number instead of a string. Signed-off-by: Ferdinand Thiessen <[email protected]>
- Loading branch information
Showing
2 changed files
with
54 additions
and
3 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
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,50 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import NcInputField from '../../../../src/components/NcInputField/index.js' | ||
|
||
|
||
describe('NcInputField', () => { | ||
it('should emit text when type is text', () => { | ||
const wrapper = shallowMount(NcInputField, { | ||
propsData: { | ||
value: '', | ||
type: 'text', | ||
}, | ||
}) | ||
|
||
const input = wrapper.find('input').element as HTMLInputElement | ||
input.value = 'text' | ||
input.dispatchEvent(new InputEvent('input')) | ||
|
||
expect(wrapper.emitted('update:value')).toEqual([['text']]) | ||
}) | ||
|
||
it('should emit text when type is number but value is text', () => { | ||
const wrapper = shallowMount(NcInputField, { | ||
propsData: { | ||
value: '1', | ||
type: 'number', | ||
}, | ||
}) | ||
|
||
const input = wrapper.find('input').element as HTMLInputElement | ||
input.value = '2' | ||
input.dispatchEvent(new InputEvent('input')) | ||
|
||
expect(wrapper.emitted('update:value')).toEqual([['2']]) | ||
}) | ||
|
||
it('should emit a number when type is number and value is number', () => { | ||
const wrapper = shallowMount(NcInputField, { | ||
propsData: { | ||
value: 1, | ||
type: 'number', | ||
}, | ||
}) | ||
|
||
const input = wrapper.find('input').element as HTMLInputElement | ||
input.value = '2' | ||
input.dispatchEvent(new InputEvent('input')) | ||
|
||
expect(wrapper.emitted('update:value')).toEqual([[2]]) | ||
}) | ||
}) |