Skip to content

Commit 9dad200

Browse files
committed
test: mock usePackageScore in a11y tests
1 parent fd94b75 commit 9dad200

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

test/nuxt/a11y.spec.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { VueWrapper } from '@vue/test-utils'
44
import 'axe-core'
55
import type { AxeResults, RunOptions } from 'axe-core'
66
import { afterEach, describe, expect, it } from 'vitest'
7+
import { ref } from 'vue'
78

89
// axe-core is a UMD module that exposes itself as window.axe in the browser
910
declare const axe: {
@@ -1013,9 +1014,52 @@ describe('component accessibility audits', () => {
10131014
})
10141015

10151016
describe('PackageScoreBars', () => {
1016-
it('should have no accessibility violations', async () => {
1017+
it('should have no accessibility violations with score data', async () => {
1018+
const component = await mountSuspended(PackageScoreBars, {
1019+
props: { packageName: 'vue' },
1020+
global: {
1021+
mocks: {
1022+
usePackageScore: () => ({
1023+
data: ref({
1024+
final: 0.85,
1025+
detail: { quality: 0.82, popularity: 0.91, maintenance: 0.78 },
1026+
}),
1027+
status: ref('success'),
1028+
}),
1029+
},
1030+
},
1031+
})
1032+
const results = await runAxe(component)
1033+
expect(results.violations).toEqual([])
1034+
})
1035+
1036+
it('should have no accessibility violations in loading state', async () => {
1037+
const component = await mountSuspended(PackageScoreBars, {
1038+
props: { packageName: 'vue' },
1039+
global: {
1040+
mocks: {
1041+
usePackageScore: () => ({
1042+
data: ref(null),
1043+
status: ref('pending'),
1044+
}),
1045+
},
1046+
},
1047+
})
1048+
const results = await runAxe(component)
1049+
expect(results.violations).toEqual([])
1050+
})
1051+
1052+
it('should have no accessibility violations when unavailable', async () => {
10171053
const component = await mountSuspended(PackageScoreBars, {
10181054
props: { packageName: 'vue' },
1055+
global: {
1056+
mocks: {
1057+
usePackageScore: () => ({
1058+
data: ref(null),
1059+
status: ref('error'),
1060+
}),
1061+
},
1062+
},
10191063
})
10201064
const results = await runAxe(component)
10211065
expect(results.violations).toEqual([])

0 commit comments

Comments
 (0)