Skip to content

Commit c144ed0

Browse files
chore: fix unit tests
1 parent a5402e1 commit c144ed0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

code/core/src/common/utils/validate-config.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest';
22

3+
import { resolveModulePath } from 'exsolve';
4+
35
import { validateFrameworkName } from './validate-config';
46

7+
// mock exsolve to spy
8+
vi.mock('exsolve', { spy: true });
9+
510
describe('validateFrameworkName', () => {
611
afterEach(() => {
712
vi.resetAllMocks();
@@ -20,21 +25,20 @@ describe('validateFrameworkName', () => {
2025
});
2126

2227
it('should not throw if framework is unknown (community) but can be resolved', () => {
23-
// mock require.resolve to return a value
24-
vi.spyOn(require, 'resolve').mockReturnValue('some-community-framework');
25-
expect(() => validateFrameworkName('some-community-framework')).toThrow();
28+
vi.mocked(resolveModulePath).mockImplementation(() => {});
29+
30+
expect(() => validateFrameworkName('some-community-framework')).not.toThrow();
2631
});
2732

2833
it('should not throw if scoped framework is unknown (community) but can be resolved', () => {
29-
// mock require.resolve to return a value
30-
vi.spyOn(require, 'resolve').mockReturnValue('@some-community/framework');
34+
vi.mocked(resolveModulePath).mockImplementation(() => {});
35+
3136
expect(() => validateFrameworkName('@some-community/framework')).not.toThrow();
32-
});
37+
});
3338

3439
it('should throw if framework is unknown and cannot be resolved', () => {
35-
// mock require.resolve to fail
36-
vi.spyOn(require, 'resolve').mockImplementation(() => {
37-
throw new Error('Cannot resolve');
40+
vi.mocked(resolveModulePath).mockImplementation(() => {
41+
throw new Error('cannot resolve');
3842
});
3943

4044
expect(() => validateFrameworkName('foo')).toThrow();

0 commit comments

Comments
 (0)