🌐 AI搜索 & 代理 主页
Skip to content

Commit 9e207fc

Browse files
committed
Update nav-item-dropdown.spec.js
1 parent a5aca94 commit 9e207fc

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/components/nav/nav-item-dropdown.spec.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('nav-item-dropdown', () => {
8787
await waitNT(wrapper.vm)
8888

8989
expect(wrapper.element.hasAttribute('id')).toBe(true)
90-
expect(wrapper.attributes('id').toEqual('foo')
90+
expect(wrapper.attributes('id')).toEqual('foo')
9191

9292
const $toggle = wrapper.find('.dropdown-toggle')
9393
expect($toggle.attributes('href')).toEqual('#foo')
@@ -172,6 +172,65 @@ describe('nav-item-dropdown', () => {
172172
wrapper.destroy()
173173
})
174174

175+
it('should have correct menu content for "default" slot', async () => {
176+
let slotScope = null
177+
const wrapper = mount(BNavItemDropdown, {
178+
scopedSlots: {
179+
default(scope) {
180+
slotScope = scope
181+
return this.$createElement('div', 'foo')
182+
}
183+
}
184+
})
185+
186+
expect(wrapper.vm).toBeDefined()
187+
await waitNT(wrapper.vm)
188+
189+
const $menu = wrapper.find('.dropdown-menu')
190+
expect($menu.find('div').exists()).toBe(true)
191+
expect($menu.text()).toEqual('foo')
192+
193+
expect(slotScope).toBeDefined()
194+
expect(slotScope.hide).toBeDefined()
195+
196+
wrapper.destroy()
197+
})
198+
199+
it('should only render menu content when visible when "lazy" prop set', async () => {
200+
const wrapper = mount(BNavItemDropdown, {
201+
propsData: {
202+
lazy: true
203+
},
204+
scopedSlots: {
205+
default() {
206+
return this.$createElement('div', 'bar')
207+
}
208+
}
209+
})
210+
211+
expect(wrapper.vm).toBeDefined()
212+
expect(wrapper.vm.visible).toBe(false)
213+
await waitNT(wrapper.vm)
214+
215+
const $menu = wrapper.find('.dropdown-menu')
216+
expect($menu.find('div').exists()).toBe(false)
217+
218+
wrapper.vm.show()
219+
await waitNT(wrapper.vm)
220+
await waitRAF()
221+
expect(wrapper.vm.visible).toBe(true)
222+
expect($menu.find('div').exists()).toBe(true)
223+
expect($menu.text()).toEqual('bar')
224+
225+
wrapper.vm.hide()
226+
await waitNT(wrapper.vm)
227+
await waitRAF()
228+
expect(wrapper.vm.visible).toBe(false)
229+
expect($menu.find('div').exists()).toBe(false)
230+
231+
wrapper.destroy()
232+
})
233+
175234
it('should open/close on toggle click', async () => {
176235
const wrapper = mount(BNavItemDropdown)
177236

0 commit comments

Comments
 (0)