Skip to content

Commit

Permalink
refactor: validPlugin and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterliu1003 committed Apr 3, 2021
1 parent c041371 commit 8e2b590
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/VueFinalModal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/VueFinalModal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/VueFinalModal.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/VueFinalModal.umd.js.map

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions lib/Plugin.js
Expand Up @@ -8,7 +8,7 @@ const defaultOptions = {
}

const validPlugin = (duplicateKey, duplicateComponent, duplicateDynamicContainer) => {
if (!(duplicateComponent || duplicateDynamicContainer)) return true
if (!(duplicateKey || duplicateComponent || duplicateDynamicContainer)) return true

if (typeof window === 'undefined') return false

Expand All @@ -26,11 +26,8 @@ const Plugin = pluginOptions => ({
const duplicateComponent = Vue.options.components[_options.componentName]
const duplicateDynamicContainer = Vue.options.components[_options.dynamicContainerName]

const isValid = validPlugin(duplicateKey, duplicateComponent, duplicateDynamicContainer)
if (isValid) {
if (!duplicateKey) {
bindPrototype(Vue, _options)
}
if (validPlugin(duplicateKey, duplicateComponent, duplicateDynamicContainer)) {
bindPrototype(Vue, _options)
registModal(Vue, _options)
registContainer(Vue, _options)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Plugin.spec.js
Expand Up @@ -29,7 +29,7 @@ describe('Plugin', () => {
dynamicContainerName: 'TestContainer'
})
)
expect(spy).toHaveBeenCalledTimes(0)
expect(spy).toHaveBeenCalledTimes(1)
})
it('duplicate component', () => {
const spy = createSpyError()
Expand Down

0 comments on commit 8e2b590

Please sign in to comment.