mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-11-27 04:09:51 +08:00
fix: some tests
This commit is contained in:
parent
48acc3f1b1
commit
22617d99df
@ -3,25 +3,7 @@
|
||||
module.exports = {
|
||||
presets:
|
||||
process.env.NODE_ENV === 'test'
|
||||
? [
|
||||
['@babel/preset-env', { targets: { node: 'current' } }],
|
||||
[
|
||||
'@babel/preset-typescript',
|
||||
{
|
||||
allExtensions: true,
|
||||
isTSX: true,
|
||||
jsxPragma: 'h',
|
||||
jsxPragmaFrag: 'Fragment'
|
||||
}
|
||||
],
|
||||
[
|
||||
'@babel/preset-react',
|
||||
{
|
||||
pragma: 'h',
|
||||
pragmaFrag: 'Fragment'
|
||||
}
|
||||
]
|
||||
]
|
||||
? [['@babel/preset-env', { targets: { node: 'current' } }]]
|
||||
: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
|
@ -65,8 +65,6 @@
|
||||
"@babel/generator": "^7.12.11",
|
||||
"@babel/parser": "^7.12.11",
|
||||
"@babel/preset-env": "^7.12.10",
|
||||
"@babel/preset-react": "^7.12.13",
|
||||
"@babel/preset-typescript": "^7.12.16",
|
||||
"@babel/traverse": "^7.12.12",
|
||||
"@rollup/plugin-babel": "^5.3.0",
|
||||
"@types/estree": "^0.0.50",
|
||||
|
@ -18,12 +18,7 @@ export type Value = number | [number, number]
|
||||
|
||||
export type Shortcuts =
|
||||
| Record<string, number | (() => number)>
|
||||
| Record<
|
||||
string,
|
||||
| [number, number]
|
||||
| readonly [number, number]
|
||||
| (() => [number, number] | readonly [number, number])
|
||||
>
|
||||
| Record<string, [number, number] | (() => [number, number])>
|
||||
|
||||
export type OnUpdateValue = (
|
||||
value: number & (number | null) & [number, number] & ([number, number] | null)
|
||||
|
@ -11,12 +11,12 @@ describe('n-date-picker', () => {
|
||||
})
|
||||
|
||||
it('date type should work with shortcuts prop', async () => {
|
||||
const test = ref<Value>(0)
|
||||
const test = ref<[number, number]>([0, 0])
|
||||
const wrapper = mount(NDatePicker, {
|
||||
props: {
|
||||
value: test.value,
|
||||
type: 'date',
|
||||
onUpdateValue: (value: Value) => {
|
||||
onUpdateValue: (value: [number, number]) => {
|
||||
test.value = value
|
||||
},
|
||||
shortcuts: {
|
||||
@ -30,8 +30,8 @@ describe('n-date-picker', () => {
|
||||
?.querySelector('.n-button') as HTMLElement
|
||||
button.click()
|
||||
expect(test.value).toEqual(1631203200000)
|
||||
test.value = 0
|
||||
wrapper.setProps({
|
||||
test.value = [0, 0]
|
||||
await wrapper.setProps({
|
||||
type: 'datetime'
|
||||
})
|
||||
await wrapper.find('.n-input').trigger('click')
|
||||
@ -64,7 +64,7 @@ describe('n-date-picker', () => {
|
||||
button.click()
|
||||
expect(test.value).toEqual([1629216000000, 1631203200000])
|
||||
test.value = 0
|
||||
wrapper.setProps({
|
||||
await wrapper.setProps({
|
||||
type: 'datetimerange'
|
||||
})
|
||||
await wrapper.find('.n-input').trigger('click')
|
||||
@ -97,7 +97,7 @@ describe('n-date-picker', () => {
|
||||
button.click()
|
||||
expect(test.value).toEqual(1631203200000)
|
||||
test.value = 0
|
||||
wrapper.setProps({
|
||||
await wrapper.setProps({
|
||||
type: 'datetime'
|
||||
})
|
||||
await wrapper.find('.n-input').trigger('click')
|
||||
@ -111,6 +111,7 @@ describe('n-date-picker', () => {
|
||||
|
||||
it('range type should work with shortcuts prop with function value', async () => {
|
||||
const test = ref<[number, number]>([0, 0])
|
||||
|
||||
const wrapper = mount(NDatePicker, {
|
||||
props: {
|
||||
value: test.value,
|
||||
@ -119,8 +120,8 @@ describe('n-date-picker', () => {
|
||||
test.value = value
|
||||
},
|
||||
shortcuts: {
|
||||
Good: [123, 456] as const,
|
||||
'Honey birthday': () => [1629216000000, 1631203200000] as const
|
||||
'Honey birthday': () =>
|
||||
[1629216000000, 1631203200000] as [number, number]
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -131,7 +132,7 @@ describe('n-date-picker', () => {
|
||||
button.click()
|
||||
expect(test.value).toEqual([1629216000000, 1631203200000])
|
||||
test.value = [0, 0]
|
||||
wrapper.setProps({
|
||||
await wrapper.setProps({
|
||||
type: 'datetimerange'
|
||||
})
|
||||
await wrapper.find('.n-input').trigger('click')
|
@ -114,7 +114,11 @@ describe('n-tabs', () => {
|
||||
tab={directive}
|
||||
name={directive}
|
||||
>
|
||||
{{ default: () => <span class={`test-${directive}`} /> }}
|
||||
{{
|
||||
default: () => (
|
||||
<span class={`test-${directive.replace(':', '-')}`} />
|
||||
)
|
||||
}}
|
||||
</NTabPane>
|
||||
))
|
||||
}
|
||||
@ -122,14 +126,14 @@ describe('n-tabs', () => {
|
||||
await wrapper.setProps({ value: 'if' })
|
||||
expect(wrapper.find('.test-show').exists()).toEqual(true)
|
||||
expect(wrapper.find('.test-if').exists()).toEqual(true)
|
||||
expect(wrapper.find('.test-show:lazy').exists()).toEqual(false)
|
||||
expect(wrapper.find('.test-show-lazy').exists()).toEqual(false)
|
||||
await wrapper.setProps({ value: 'show:lazy' })
|
||||
expect(wrapper.find('.test-show').exists()).toEqual(true)
|
||||
expect(wrapper.find('.test-if').exists()).toEqual(false)
|
||||
expect(wrapper.find('.test-show:lazy').exists()).toEqual(true)
|
||||
expect(wrapper.find('.test-show-lazy').exists()).toEqual(true)
|
||||
await wrapper.setProps({ value: 'show' })
|
||||
expect(wrapper.find('.test-show').exists()).toEqual(true)
|
||||
expect(wrapper.find('.test-if').exists()).toEqual(false)
|
||||
expect(wrapper.find('.test-show:lazy').exists()).toEqual(true)
|
||||
expect(wrapper.find('.test-show-lazy').exists()).toEqual(true)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user