test(NLayout): add test (#815)

This commit is contained in:
XieZongChen 2021-08-08 09:58:17 -05:00 committed by GitHub
parent 8febb56c99
commit 79eabff54c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,64 @@
import { h } from 'vue'
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import { NLayout } from '../index' import {
NLayout,
NLayoutContent,
NLayoutFooter,
NLayoutHeader,
NLayoutSider
} from '../index'
describe('n-layout', () => { describe('n-layout', () => {
it('should work with import on demand', () => { it('should work with import on demand', () => {
mount(NLayout) mount(NLayout)
}) })
it('should work with Basic', async () => {
const wrapper = mount(NLayout, {
props: {
'has-sider': true
},
slots: {
default: () => [
h(NLayoutHeader, null, { default: () => 'test-header' }),
h(NLayoutContent, null, { default: () => 'test-content' }),
h(NLayoutSider, null, { default: () => 'test-sider' }),
h(NLayoutFooter, null, { default: () => 'test-footer' })
]
}
})
console.log(wrapper.html())
expect(
wrapper.find('.n-layout-scroll-container').element.children.length
).toBe(4)
expect(
wrapper
.find('.n-layout-scroll-container')
.element.children[0].getAttribute('class')
).toContain('n-layout-header')
expect(wrapper.find('.n-layout-header').text()).toBe('test-header')
expect(
wrapper
.find('.n-layout-scroll-container')
.element.children[1].getAttribute('class')
).toContain('n-layout-content')
expect(wrapper.findAll('.n-layout-scroll-container')[1].text()).toBe(
'test-content'
)
expect(
wrapper
.find('.n-layout-scroll-container')
.element.children[2].getAttribute('class')
).toContain('n-layout-sider')
expect(wrapper.find('.n-layout-sider-scroll-container').text()).toBe(
'test-sider'
)
expect(
wrapper
.find('.n-layout-scroll-container')
.element.children[3].getAttribute('class')
).toContain('n-layout-footer')
expect(wrapper.find('.n-layout-footer').text()).toBe('test-footer')
})
}) })