Skip to content

Commit 4e29908

Browse files
committed
chore: add non-null assertion to tests
1 parent e6ff285 commit 4e29908

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

test/nuxt/server/utils/dependency-analysis.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { describe, expect, it, vi, beforeEach } from 'vitest'
22

33
// Mock Nitro globals before importing the module
44
vi.stubGlobal('defineCachedFunction', (fn: Function) => fn)
5-
vi.stubGlobal('$fetch', vi.fn())
5+
const $fetchMock = vi.fn()
6+
vi.stubGlobal('$fetch', $fetchMock)
67

78
// Import module under test
89
const { analyzeDependencyTree } = await import('../../../../server/utils/dependency-analysis')
@@ -26,7 +27,7 @@ function mockOsvApi(
2627
batchResults: Array<{ vulns?: Array<{ id: string; modified: string }> }>,
2728
detailResults: Map<string, { vulns?: Array<Record<string, unknown>> }> = new Map(),
2829
) {
29-
vi.mocked($fetch).mockImplementation(async (url: string, options?: { body?: unknown }) => {
30+
$fetchMock.mockImplementation(async (url: string, options?: { body?: unknown }) => {
3031
if (url === 'https://api.osv.dev/v1/querybatch') {
3132
return { results: batchResults }
3233
}
@@ -102,7 +103,7 @@ describe('dependency-analysis', () => {
102103
vi.mocked(resolveDependencyTree).mockResolvedValue(mockResolved)
103104

104105
// Batch query fails entirely
105-
vi.mocked($fetch).mockRejectedValue(new Error('OSV API error'))
106+
$fetchMock.mockRejectedValue(new Error('OSV API error'))
106107

107108
const result = await analyzeDependencyTree('test-pkg', '1.0.0')
108109

test/nuxt/server/utils/readme.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('Playground Link Extraction', () => {
4747
const result = await renderReadmeHtml(markdown, 'test-pkg')
4848

4949
expect(result.playgroundLinks).toHaveLength(1)
50-
expect(result.playgroundLinks[0].provider).toBe('codesandbox')
50+
expect(result.playgroundLinks[0]!.provider).toBe('codesandbox')
5151
})
5252
})
5353

@@ -56,21 +56,21 @@ describe('Playground Link Extraction', () => {
5656
const markdown = `[Pen](https://codepen.io/user/pen/abc123)`
5757
const result = await renderReadmeHtml(markdown, 'test-pkg')
5858

59-
expect(result.playgroundLinks[0].provider).toBe('codepen')
59+
expect(result.playgroundLinks[0]!.provider).toBe('codepen')
6060
})
6161

6262
it('extracts Replit links', async () => {
6363
const markdown = `[Repl](https://replit.com/@user/project)`
6464
const result = await renderReadmeHtml(markdown, 'test-pkg')
6565

66-
expect(result.playgroundLinks[0].provider).toBe('replit')
66+
expect(result.playgroundLinks[0]!.provider).toBe('replit')
6767
})
6868

6969
it('extracts Gitpod links', async () => {
7070
const markdown = `[Open in Gitpod](https://gitpod.io/#https://github.com/user/repo)`
7171
const result = await renderReadmeHtml(markdown, 'test-pkg')
7272

73-
expect(result.playgroundLinks[0].provider).toBe('gitpod')
73+
expect(result.playgroundLinks[0]!.provider).toBe('gitpod')
7474
})
7575
})
7676

@@ -83,8 +83,8 @@ describe('Playground Link Extraction', () => {
8383
const result = await renderReadmeHtml(markdown, 'test-pkg')
8484

8585
expect(result.playgroundLinks).toHaveLength(2)
86-
expect(result.playgroundLinks[0].provider).toBe('stackblitz')
87-
expect(result.playgroundLinks[1].provider).toBe('codesandbox')
86+
expect(result.playgroundLinks[0]!.provider).toBe('stackblitz')
87+
expect(result.playgroundLinks[1]!.provider).toBe('codesandbox')
8888
})
8989

9090
it('deduplicates same URL', async () => {
@@ -127,7 +127,7 @@ describe('Playground Link Extraction', () => {
127127
const result = await renderReadmeHtml(markdown, 'test-pkg')
128128

129129
expect(result.playgroundLinks).toHaveLength(1)
130-
expect(result.playgroundLinks[0].provider).toBe('stackblitz')
130+
expect(result.playgroundLinks[0]!.provider).toBe('stackblitz')
131131
})
132132
})
133133
})

0 commit comments

Comments
 (0)