test(components): removing mock folder (#5911)

- Remove mock folder from the project root
- Add mock for each component test file accordingly
This commit is contained in:
jeremywu
2022-02-10 16:35:44 +08:00
committed by GitHub
parent 40b0f963c6
commit bcd5c8b848
12 changed files with 98 additions and 16 deletions

View File

@@ -1,5 +0,0 @@
module.exports = jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
})

View File

@@ -1,6 +0,0 @@
const _ = jest.requireActual('lodash')
_.debounce = require('./debounce')
_.throttle = require('./throttle')
module.exports = _

View File

@@ -1,5 +0,0 @@
module.exports = jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
})

View File

@@ -6,6 +6,17 @@ import { ArrowDown, Check, CircleClose } from '@element-plus/icons-vue'
import { POPPER_CONTAINER_SELECTOR } from '@element-plus/hooks'
import Cascader from '../src/index.vue'
jest.mock('lodash-unified', () => {
return {
...(jest.requireActual('lodash-unified') as Record<string, any>),
debounce: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
const OPTIONS = [
{
value: 'zhejiang',

View File

@@ -5,6 +5,17 @@ import type { ComponentPublicInstance } from 'vue'
import type { Nullable } from '@element-plus/utils/types'
jest.mock('lodash-unified', () => {
return {
...(jest.requireActual('lodash-unified') as Record<string, any>),
debounce: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
const _mount = (template: string, data: () => { [key: string]: any }) => {
const Component = defineComponent({
components: {

View File

@@ -3,6 +3,16 @@ import { mount } from '@vue/test-utils'
import { tick, defineGetter, makeScroll } from '@element-plus/test-utils'
import InfiniteScroll, { SCOPE, DEFAULT_DELAY } from '../src/index'
jest.mock('lodash-unified', () => {
return {
throttle: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
const CONTAINER_HEIGHT = 200
const ITEM_HEIGHT = 100
const CONTAINER_STYLE = `overflow-y: auto;`

View File

@@ -8,6 +8,17 @@ import { hasClass } from '@element-plus/utils/dom'
import { POPPER_CONTAINER_SELECTOR } from '@element-plus/hooks'
import Select from '../src/select.vue'
jest.mock('lodash-unified', () => {
return {
...(jest.requireActual('lodash-unified') as Record<string, any>),
debounce: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
jest.useFakeTimers()
const _mount = makeMountFunc({

View File

@@ -7,6 +7,17 @@ import Select from '../src/select.vue'
import Group from '../src/option-group.vue'
import Option from '../src/option.vue'
jest.mock('lodash-unified', () => {
return {
...(jest.requireActual('lodash-unified') as Record<string, any>),
debounce: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
jest.useFakeTimers()
interface SelectProps {

View File

@@ -2,6 +2,17 @@ import { h, nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import Slider from '../src/index.vue'
jest.mock('lodash-unified', () => {
return {
...(jest.requireActual('lodash-unified') as Record<string, any>),
debounce: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
describe('Slider', () => {
it('create', () => {
const wrapper = mount(Slider)

View File

@@ -4,6 +4,17 @@ import ElTable from '../src/table.vue'
import ElTableColumn from '../src/table-column/index'
import { mount, getTestData } from './table-test-common'
jest.mock('lodash-unified', () => {
return {
...(jest.requireActual('lodash-unified') as Record<string, any>),
debounce: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
describe('table column', () => {
describe('column attributes', () => {
const createTable = function (

View File

@@ -1,5 +1,16 @@
import { mount as _mount } from '@vue/test-utils'
jest.mock('lodash-unified', () => {
return {
...(jest.requireActual('lodash-unified') as Record<string, any>),
debounce: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
export const mount = (opt: any) =>
_mount<any>(opt, {
attachTo: 'body',

View File

@@ -10,6 +10,17 @@ import type { ComponentPublicInstance } from 'vue'
const { CheckboxGroup: ElCheckboxGroup } = ElCheckbox
jest.mock('lodash-unified', () => {
return {
...(jest.requireActual('lodash-unified') as Record<string, any>),
debounce: jest.fn((fn) => {
fn.cancel = jest.fn()
fn.flush = jest.fn()
return fn
}),
}
})
jest.useFakeTimers()
describe('Table.vue', () => {