22 lines
1.3 KiB
TypeScript
22 lines
1.3 KiB
TypeScript
/**
|
|
* 45-news: Apple News Vue 组件化测试
|
|
* 覆盖: 4 篇文章卡片、分类/标题/描述、卸载
|
|
*/
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import { h, render } from 'vue'
|
|
import NewsComponent from '../../src/apps/news/News.vue'
|
|
import { setupDOM } from '../helpers'
|
|
|
|
describe('45-news', () => {
|
|
let body: HTMLElement
|
|
beforeEach(() => { setupDOM(); const el = document.createElement('div'); el.className = 'window'; document.body.appendChild(el); body = document.createElement('div'); body.className = 'win-body'; el.appendChild(body); (window as any).WM = { setTitle() {} } })
|
|
afterEach(() => { render(null, body); (body.parentElement as HTMLElement)?.remove() })
|
|
function m() { render(h(NewsComponent, {}), body) }
|
|
|
|
it('4 篇文章', () => { m(); expect(body.querySelectorAll('.news-card').length).toBe(4) })
|
|
it('每篇有分类标签', () => { m(); expect(body.querySelector('.news-cat')?.textContent).toBeTruthy() })
|
|
it('每篇有标题', () => { m(); expect(body.querySelector('.news-title')?.textContent).toContain('macOS') })
|
|
it('每篇有描述', () => { m(); expect(body.querySelector('.news-desc')?.textContent).toBeTruthy() })
|
|
it('卸载', () => { m(); render(null, body); expect(body.children.length).toBe(0) })
|
|
})
|