20 lines
1.0 KiB
JavaScript
20 lines
1.0 KiB
JavaScript
|
|
import { expect, it } from 'vitest'
|
||
|
|
import { mount } from '@vue/test-utils'
|
||
|
|
import { ref, watch, onMounted, nextTick } from 'vue'
|
||
|
|
// Production component uses the application's auto-imported Vue APIs.
|
||
|
|
Object.assign(globalThis,{ref,watch,onMounted})
|
||
|
|
import Result from '../../src/components/Crontab/result.vue'
|
||
|
|
it('invalid or incomplete expressions show a useful result instead of hanging or throwing',async()=>{
|
||
|
|
for(const ex of ['0/0 * * * * ?','0/-1 * * * * ?','','0 0','0 0 0 * * ? 1970-999999999','999 0 0 * * ?','x 0 0 * * ?']){
|
||
|
|
const wrapper=mount(Result,{props:{ex}})
|
||
|
|
await nextTick()
|
||
|
|
expect(wrapper.text()).toContain('间隔须大于 0');wrapper.unmount()
|
||
|
|
}
|
||
|
|
})
|
||
|
|
it('normal expressions still produce five future runs',async()=>{
|
||
|
|
for(const ex of ['0/15 * * * * ?','0 0 9 * * ?','0 0 9 1 * ?','0 0 9 ? * 2-6']){
|
||
|
|
const wrapper=mount(Result,{props:{ex}});await nextTick()
|
||
|
|
expect(wrapper.findAll('li')).toHaveLength(5);expect(wrapper.text()).not.toContain('暂无法预览');wrapper.unmount()
|
||
|
|
}
|
||
|
|
})
|