|
| 1 | +import { afterEach, describe, expect, it, vi } from 'vitest' |
| 2 | +import { mountSuspended } from '@nuxt/test-utils/runtime' |
| 3 | +import type { VueWrapper } from '@vue/test-utils' |
| 4 | +import { ref } from 'vue' |
| 5 | +import PackageMetricsBadges from '~/components/Package/MetricsBadges.vue' |
| 6 | + |
| 7 | +const mockUsePackageAnalysis = vi.fn() |
| 8 | + |
| 9 | +vi.mock('~/composables/usePackageAnalysis', () => ({ |
| 10 | + usePackageAnalysis: mockUsePackageAnalysis, |
| 11 | +})) |
| 12 | + |
| 13 | +describe('PackageMetricsBadges', () => { |
| 14 | + let wrapper: VueWrapper |
| 15 | + |
| 16 | + afterEach(() => wrapper?.unmount()) |
| 17 | + |
| 18 | + it('renders the badges', async () => { |
| 19 | + mockUsePackageAnalysis.mockReturnValue({ |
| 20 | + data: ref({ moduleFormat: 'dual', types: { kind: 'included' } }), |
| 21 | + status: ref('success'), |
| 22 | + }) |
| 23 | + |
| 24 | + wrapper = await mountSuspended(PackageMetricsBadges, { |
| 25 | + props: { packageName: 'test-pkg' }, |
| 26 | + }) |
| 27 | + |
| 28 | + const text = wrapper.text() |
| 29 | + expect(text).toContain('Types') |
| 30 | + expect(text).toContain('ESM') |
| 31 | + expect(text).toContain('CJS') |
| 32 | + }) |
| 33 | + |
| 34 | + it('renders the wasm label', async () => { |
| 35 | + mockUsePackageAnalysis.mockReturnValue({ |
| 36 | + data: ref({ moduleFormat: 'wasm' }), |
| 37 | + status: ref('success'), |
| 38 | + }) |
| 39 | + |
| 40 | + wrapper = await mountSuspended(PackageMetricsBadges, { |
| 41 | + props: { packageName: 'wasm-pkg' }, |
| 42 | + }) |
| 43 | + |
| 44 | + const text = wrapper.text() |
| 45 | + expect(text).toContain('WASM') |
| 46 | + }) |
| 47 | +}) |
0 commit comments