diff --git a/package.json b/package.json index b8484cf842..1cb57e4ab4 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,10 @@ "@storybook/html": "^5.3.19", "@swc-node/jest": "^0.1.9", "@types/jest": "^26.0.7", +<<<<<<< HEAD +======= + "@types/lodash": "^4.14.159", +>>>>>>> chore(popper): replace lodash with lodash-es "@typescript-eslint/eslint-plugin": "^3.7.0", "@typescript-eslint/parser": "^3.7.0", "@vue/compiler-sfc": "^3.0.0-rc.1", diff --git a/packages/popper/__mocks__/lodash-es.js b/packages/popper/__mocks__/lodash-es.js deleted file mode 100644 index 91c771b4fc..0000000000 --- a/packages/popper/__mocks__/lodash-es.js +++ /dev/null @@ -1,8 +0,0 @@ - -const _ = jest.genMockFromModule('lodash-es') - -const debounce = (fn) => () => fn() - -_.debounce = debounce - -module.exports = _ diff --git a/packages/popper/__mocks__/lodash.js b/packages/popper/__mocks__/lodash.js new file mode 100644 index 0000000000..5212a40214 --- /dev/null +++ b/packages/popper/__mocks__/lodash.js @@ -0,0 +1,16 @@ + +const _ = jest.genMockFromModule('lodash') + + +const debounce = jest.fn(fn => { + const caller = () => { + return fn() + } + caller.cancel = jest.fn() + caller.flush = jest.fn() + return caller +}) + +_.debounce = debounce + +module.exports = _ diff --git a/packages/popper/__tests__/popper.spec.ts b/packages/popper/__tests__/popper.spec.ts index 9fc623a5a9..6fc2c20d3e 100644 --- a/packages/popper/__tests__/popper.spec.ts +++ b/packages/popper/__tests__/popper.spec.ts @@ -6,13 +6,14 @@ import ElPopper from '../src/index.vue' import type { VueWrapper } from '@vue/test-utils' +type UnKnownProps = Record + +jest.mock('lodash') + const AXIOM = 'Rem is the best girl' +const Wrapped = (props: UnKnownProps, { slots }) => h('div', h(ElPopper, props, slots)) -jest.mock('lodash-es') - -const Wrapped = (props, { slots }) => h('div', h(ElPopper, props, slots)) - -const Transition = (_, { attrs, slots }) => h('div', attrs, slots) +const Transition = (_: UnKnownProps, { attrs, slots }) => h('div', attrs, slots) Transition.displayName = 'Transition' // eslint-disable-next-line const _mount = (props: Record = {}, slots = {}): VueWrapper => @@ -24,20 +25,23 @@ const _mount = (props: Record = {}, slots = {}): VueWrapper ({ + update: jest.fn(), + forceUpdate: jest.fn(), + setOptions: jest.fn(), + destroy: jest.fn(), + state: null, +})) + describe('Popper.vue', () => { - let popperMock + // eslint-disable-next-line + // eslint-disable-next-line const oldTransition = Vue.Transition beforeAll(() => { - popperMock = jest.spyOn(popperExports, 'createPopper').mockImplementation(() => ({ - update: jest.fn(), - forceUpdate: jest.fn(), - setOptions: jest.fn(), - destroy: jest.fn(), - state: null, - })) // eslint-disable-next-line ;(Vue as any).Transition = Transition }) + afterAll(() => { popperMock.mockReset() // eslint-disable-next-line @@ -110,6 +114,7 @@ describe('Popper.vue', () => { }) expect(wrapper.find(selector).attributes('style')).toContain('display: none') await wrapper.find(selector).trigger('mouseenter') + expect(wrapper.find(selector).attributes('style')).toContain('display: none') await wrapper.setProps({ value: true, @@ -134,8 +139,8 @@ describe('Popper.vue', () => { await wrapper.setProps({ disabled: false, }) - await wrapper.find(selector).trigger('mouseenter') + expect(wrapper.find(selector).attributes('style')).not.toContain('display: none') }) diff --git a/packages/popper/src/index.vue b/packages/popper/src/index.vue index 3919ca41ad..5c4f946581 100644 --- a/packages/popper/src/index.vue +++ b/packages/popper/src/index.vue @@ -32,11 +32,10 @@ import { ref, onBeforeUnmount, onMounted, - onUnmounted, watch, } from 'vue' import { isArray } from '@vue/shared' -import { debounce } from 'lodash-es' +import { debounce } from 'lodash' import { createPopper } from '@popperjs/core' import { generateId } from '@element-plus/utils/util' diff --git a/packages/utils/popup.ts b/packages/utils/popup.ts deleted file mode 100644 index ca4a4a6982..0000000000 --- a/packages/utils/popup.ts +++ /dev/null @@ -1 +0,0 @@ -export const PopupManager = {} diff --git a/packages/utils/util.ts b/packages/utils/util.ts index 240e57e78e..7c9bf85333 100644 --- a/packages/utils/util.ts +++ b/packages/utils/util.ts @@ -1,9 +1,6 @@ import isServer from './isServer' -import isObject from 'lodash/isObject' -import castArray from 'lodash/castArray' -import isEmpty from 'lodash/isEmpty' -import isEqual from 'lodash/isEqual' -import capitalize from 'lodash/capitalize' +import { isObject, capitalize } from '@vue/shared' +import {isEmpty, castArray, isEqual} from 'lodash' const { hasOwnProperty } = Object.prototype diff --git a/tsconfig.json b/tsconfig.json index 33fb7975b3..1805f2eb17 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,9 @@ "sourceMap": true, "lib": [ "es2020", "dom" - ] + ], + "esModuleInterop": true, + "allowSyntheticDefaultImports": true }, "exclude": [ "node_modules" diff --git a/yarn.lock b/yarn.lock index 52fa178eb6..5f56e59ad1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2849,17 +2849,10 @@ "@types/koa-compose" "*" "@types/node" "*" -"@types/lodash-es@^4.17.3": - version "4.17.3" - resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.3.tgz#87eb0b3673b076b8ee655f1890260a136af09a2d" - integrity sha512-iHI0i7ZAL1qepz1Y7f3EKg/zUMDwDfTzitx+AlHhJJvXwenP682ZyGbgPSc5Ej3eEAKVbNWKFuwOadCj5vBbYQ== - dependencies: - "@types/lodash" "*" - -"@types/lodash@*": - version "4.14.158" - resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.158.tgz#b38ea8b6fe799acd076d7a8d7ab71c26ef77f785" - integrity sha512-InCEXJNTv/59yO4VSfuvNrZHt7eeNtWQEgnieIA+mIC+MOWM9arOWG2eQ8Vhk6NbOre6/BidiXhkZYeDY9U35w== +"@types/lodash@^4.14.159": + version "4.14.159" + resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.159.tgz#61089719dc6fdd9c5cb46efc827f2571d1517065" + integrity sha512-gF7A72f7WQN33DpqOWw9geApQPh4M3PxluMtaHxWHXEGSN12/WbcEk/eNSqWNQcQhF66VSZ06vCF94CrHwXJDg== "@types/lru-cache@^5.1.0": version "5.1.0" @@ -9585,11 +9578,6 @@ locate-path@^5.0.0: dependencies: p-locate "^4.1.0" -lodash-es@^4.17.15: - version "4.17.15" - resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78" - integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ== - lodash._reinterpolate@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"