Skip to content

Commit e7ffacb

Browse files
committed
chore: improve test assertions and cleanup
1 parent c642e4d commit e7ffacb

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

test/1.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ describe('init', () => {
5252

5353
// Example test: use vi.doMock to override the config module
5454
it('should return an array of enabled auth methods when overridden', async () => {
55-
vi.resetModules(); // Clear module cache
56-
5755
// fs must be mocked BEFORE importing the config module
5856
// We also mock existsSync to ensure the file "exists"
5957
vi.doMock('fs', async (importOriginal) => {
@@ -87,6 +85,9 @@ describe('init', () => {
8785
afterEach(function () {
8886
// Restore all stubs
8987
vi.restoreAllMocks();
88+
89+
// Clear module cache
90+
vi.resetModules();
9091
});
9192

9293
// Runs after all tests

test/extractRawBody.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, beforeEach, expect, vi, Mock } from 'vitest';
1+
import { describe, it, beforeEach, expect, vi, Mock, afterAll } from 'vitest';
22
import { PassThrough } from 'stream';
33

44
// Tell Vitest to mock dependencies
@@ -33,7 +33,9 @@ describe('extractRawBody middleware', () => {
3333
};
3434

3535
next = vi.fn();
36+
});
3637

38+
afterAll(() => {
3739
(rawBody as Mock).mockClear();
3840
(chain.executeChain as Mock).mockClear();
3941
});

test/generated-config.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,9 @@ describe('Generated Config (QuickType)', () => {
302302
});
303303

304304
it('should test validation error paths', () => {
305-
try {
306-
// Try to parse something that looks like valid JSON but has wrong structure
307-
Convert.toGitProxyConfig('{"proxyUrl": 123, "authentication": "not-array"}');
308-
} catch (error) {
309-
assert.instanceOf(error, Error);
310-
}
305+
assert.throws(() =>
306+
Convert.toGitProxyConfig('{"proxyUrl": 123, "authentication": "not-array"}'),
307+
);
311308
});
312309

313310
it('should test date and null handling', () => {

0 commit comments

Comments
 (0)