2022-01-04 09:15:15 +08:00
|
|
|
import { nextTick } from 'vue'
|
|
|
|
import { shallowMount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
2022-01-04 09:15:15 +08:00
|
|
|
import * as vueuse from '@vueuse/core'
|
2022-03-25 15:35:56 +08:00
|
|
|
import { POPPER_CONTAINER_SELECTOR, usePopperContainer } from '../src/container'
|
2022-01-04 09:15:15 +08:00
|
|
|
|
|
|
|
const AXIOM = 'rem is the best girl'
|
|
|
|
|
2022-04-19 12:46:57 +08:00
|
|
|
vi.mock('@vueuse/core', () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
return {
|
|
|
|
isClient: true,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const mountComponent = () =>
|
|
|
|
shallowMount({
|
|
|
|
template: `<div>
|
|
|
|
${AXIOM}
|
|
|
|
</div>`,
|
|
|
|
setup() {
|
|
|
|
usePopperContainer()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('usePopperContainer', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should append container to the DOM root', async () => {
|
|
|
|
mountComponent()
|
|
|
|
await nextTick()
|
|
|
|
|
|
|
|
expect(document.body.querySelector(POPPER_CONTAINER_SELECTOR)).toBeDefined()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not append container to the DOM root', async () => {
|
|
|
|
;(vueuse as any).isClient = false
|
|
|
|
mountComponent()
|
|
|
|
await nextTick()
|
|
|
|
expect(document.body.querySelector(POPPER_CONTAINER_SELECTOR)).toBeNull()
|
|
|
|
})
|
|
|
|
})
|