-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathPackageLikeCard.spec.ts
More file actions
47 lines (36 loc) · 1.46 KB
/
PackageLikeCard.spec.ts
File metadata and controls
47 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { afterEach, describe, expect, it } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import type { VueWrapper } from '@vue/test-utils'
import LikeCard from '~/components/Package/LikeCard.vue'
describe('PackageLikeCard', () => {
let wrapper: VueWrapper
afterEach(() => {
wrapper?.unmount()
})
function mountLikeCard(packageUrl: string) {
return mountSuspended(LikeCard, {
props: { packageUrl },
attachTo: document.body,
})
}
it('renders the package name', async () => {
wrapper = await mountLikeCard('https://npmx.dev/package/vue')
expect(wrapper.text()).toContain('vue')
})
it('truncates a long package name instead of overflowing', async () => {
const longName = 'a'.repeat(200)
wrapper = await mountLikeCard(`https://npmx.dev/package/${longName}`)
const nameEl = wrapper.find('span.truncate').element as HTMLElement
expect(nameEl.scrollWidth).toBeGreaterThan(nameEl.clientWidth)
})
it('shows the full name in a title attribute on hover', async () => {
const longName = 'a'.repeat(200)
wrapper = await mountLikeCard(`https://npmx.dev/package/${longName}`)
const nameEl = wrapper.find('span.truncate')
expect(nameEl.attributes('title')).toBe(longName)
})
it('extracts scoped package name from URL', async () => {
wrapper = await mountLikeCard('https://npmx.dev/package/@scope/pkg')
expect(wrapper.find('span.truncate').text()).toBe('@scope/pkg')
})
})