Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move mocks example to core tests
- Loading branch information
1 parent
6c535d6
commit b6ce2d4
Showing
65 changed files
with
424 additions
and
763 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
.../__mocks__/@vueuse/integrations/useJwt.ts → .../__mocks__/@vueuse/integrations/useJwt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { ref } from 'vue' | ||
import { vi } from 'vitest' | ||
|
||
export const useJwt = vi.fn(() => ({ | ||
payload: ref({ | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
test/mocks/__mocks__/zustand.ts → test/core/__mocks__/zustand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { vi } from 'vitest' | ||
|
||
vi.doMock('axios') |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 9 additions & 8 deletions
17
test/mocks/test/automocking.spec.ts → test/core/test/mocking/automocking.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/mocks/test/axios.test.ts → test/core/test/mocking/axios-mocked.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import axios from 'axios' | ||
import { expect, test, vi } from 'vitest' | ||
|
||
vi.mock('axios') | ||
|
||
|
1 change: 1 addition & 0 deletions
1
test/mocks/test/axios-not-mocked.test.ts → ...ore/test/mocking/axios-not-mocked.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect, test, vi } from 'vitest' | ||
// @ts-expect-error not typed | ||
import { main, mainB } from '../../src/mocks/main.js' | ||
import x from '../../src/mocks/export-default-circle-index.js' | ||
|
||
vi.mock('../../src/mocks/A', async () => ({ | ||
...(await vi.importActual<any>('../../src/mocks/A')), | ||
funcA: () => 'mockedA', | ||
})) | ||
|
||
vi.mock('../../src/mocks/B', async () => ({ | ||
...(await vi.importActual<any>('../../src/mocks/B')), | ||
funcB: () => 'mockedB', | ||
})) | ||
|
||
vi.mock('../../src/mocks/export-default-circle-b') | ||
|
||
test('can import actual inside mock factory', () => { | ||
expect(main()).toBe('mockedA') | ||
}) | ||
|
||
test('can import in top level and inside mock factory', () => { | ||
expect(mainB()).toBe('mockedB') | ||
}) | ||
|
||
test('can mock a circular dependency', () => { | ||
expect(x()).toBe(undefined) | ||
}) |
1 change: 1 addition & 0 deletions
1
...ocks/test/custom-module-directory.spec.ts → ...t/mocking/custom-module-directory.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expect, test, vi } from 'vitest' | ||
|
||
import '../../src/mocks/cyclic-deps/module-1' | ||
|
||
vi.mock('../../src/mocks/cyclic-deps/module-2', async () => { | ||
await vi.importActual('../../src/mocks/cyclic-deps/module-2') | ||
|
||
return { default: () => {} } | ||
}) | ||
|
||
test('some test', () => { | ||
expect(1 + 1).toBe(2) | ||
}) |
4 changes: 2 additions & 2 deletions
4
...mocks/test/cyclic-import-original.spec.ts → ...st/mocking/cyclic-import-original.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { expect, test, vi } from 'vitest' | ||
// @ts-expect-error mocked module | ||
import * as squaredModule from '../../../mocks/src/squared' | ||
// @ts-expect-error mocked module | ||
import { squared } from '../../../mocks/src/squared' | ||
import { foo } from '../../../mocks/src/set-foo.js' | ||
|
||
vi.mock('any') | ||
|
||
test('spyOn entire module', () => { | ||
vi.spyOn(squaredModule, 'squared') | ||
expect(squared).not.toHaveBeenCalled() | ||
}) | ||
|
||
test('foo should be 1', () => { | ||
expect(foo).toBe(1) | ||
}) |
6 changes: 4 additions & 2 deletions
6
test/mocks/test/error-mock.spec.ts → test/core/test/mocking/error-mock.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
vi.mock('../src/default', () => { | ||
import { expect, test, vi } from 'vitest' | ||
|
||
vi.mock('../../src/mocks/default', () => { | ||
throw new Error('some error') | ||
}) | ||
|
||
test('when using top level variable, gives helpful message', async () => { | ||
await expect(() => import('../src/default.js').then(m => m.default)).rejects | ||
await expect(() => import('../../src/mocks/default').then(m => m.default)).rejects | ||
.toThrowErrorMatchingInlineSnapshot(`[Error: [vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock]`) | ||
}) |
7 changes: 4 additions & 3 deletions
7
test/mocks/test/external.test.ts → test/core/test/mocking/external.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/mocks/test/has-extension.spec.ts → test/core/test/mocking/has-extension.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
test/mocks/test/integration.test.ts → test/core/test/mocking/integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
test/mocks/test/nested-default.spec.ts → .../core/test/mocking/nested-default.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
test/mocks/test/self-importing.test.ts → .../core/test/mocking/self-importing.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { expect, test, vi } from 'vitest' | ||
import { thisIsOk } from '../../src/mocks/has space in path' | ||
|
||
vi.mock('../../src/mocks/has space in path', () => ({ thisIsOk: true })) | ||
|
||
test('modules with spaces in name is mocked', () => { | ||
expect(thisIsOk).toBe(true) | ||
}) |
1 change: 1 addition & 0 deletions
1
test/mocks/test/tinyspy.test.ts → test/core/test/mocking/tinyspy.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.