|
|
@@ -15,26 +15,27 @@ beforeEach(() => {
|
|
|
afterEach(() => {
|
|
|
host.remove()
|
|
|
})
|
|
|
-
|
|
|
+const createDemo = (defaultValue: boolean) =>
|
|
|
+ defineComponent({
|
|
|
+ setup() {
|
|
|
+ const visible = ref(defaultValue)
|
|
|
+ function handleClick() {
|
|
|
+ visible.value = !visible.value
|
|
|
+ }
|
|
|
+ const t0 = template('<button>toggle</button><h1>hello world</h1>')
|
|
|
+ const n0 = t0()
|
|
|
+ const {
|
|
|
+ 0: [n1],
|
|
|
+ 1: [n2],
|
|
|
+ } = children(n0)
|
|
|
+ withDirectives(n2, [[vShow, () => visible.value]])
|
|
|
+ on(n1 as HTMLElement, 'click', handleClick)
|
|
|
+ return n0
|
|
|
+ },
|
|
|
+ })
|
|
|
describe('directive: v-show', () => {
|
|
|
test('basic', async () => {
|
|
|
- const demo = defineComponent({
|
|
|
- setup() {
|
|
|
- const visible = ref(true)
|
|
|
- function handleClick() {
|
|
|
- visible.value = !visible.value
|
|
|
- }
|
|
|
- const t0 = template('<button>toggle</button><h1>hello world</h1>')
|
|
|
- const n0 = t0()
|
|
|
- const {
|
|
|
- 0: [n1],
|
|
|
- 1: [n2],
|
|
|
- } = children(n0)
|
|
|
- withDirectives(n2, [[vShow, () => visible.value]])
|
|
|
- on(n1 as HTMLElement, 'click', (...args) => handleClick(...args))
|
|
|
- return n0
|
|
|
- },
|
|
|
- })
|
|
|
+ const demo = createDemo(true)
|
|
|
render(demo as any, {}, '#host')
|
|
|
const btn = host.querySelector('button')
|
|
|
expect(host.innerHTML).toBe('<button>toggle</button><h1>hello world</h1>')
|
|
|
@@ -44,4 +45,14 @@ describe('directive: v-show', () => {
|
|
|
'<button>toggle</button><h1 style="display: none;">hello world</h1>',
|
|
|
)
|
|
|
})
|
|
|
+ test('should hide content when default value is false', async () => {
|
|
|
+ const demo = createDemo(false)
|
|
|
+ render(demo as any, {}, '#host')
|
|
|
+ const btn = host.querySelector('button')
|
|
|
+ const h1 = host.querySelector('h1')
|
|
|
+ expect(h1?.style.display).toBe('none')
|
|
|
+ btn?.click()
|
|
|
+ await nextTick()
|
|
|
+ expect(h1?.style.display).toBe('')
|
|
|
+ })
|
|
|
})
|