-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
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,6 +1,6 @@ | ||
import { Mock, vi } from 'vitest' | ||
|
||
export const main: Mock = vi.fn().mockImplementation(() => { | ||
console.log('Fake implementation') | ||
console.log('sample: fake implementation') | ||
return false | ||
}) |
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,14 @@ | ||
import { Mock, vi } from 'vitest' | ||
|
||
export const request: Mock = vi.fn().mockImplementation(() => ({ | ||
body: { | ||
json: vi.fn().mockImplementation(() => { | ||
console.log('undici: mocked implementation') | ||
return { | ||
id: 12, | ||
quote: 'Life is what happens to you while you\'re busy making other plans.', | ||
author: 'John Lennon', | ||
} | ||
}) | ||
} | ||
})) |
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { expect, test, vi } from 'vitest' | ||
|
||
import { app } from './index' | ||
import { quote, boolean } from './index' | ||
|
||
vi.mock('sample') | ||
vi.mock('undici') | ||
|
||
test('should use a mocked dependency', () => { | ||
expect(app()).toBe(false) | ||
test('should use a mocked implementation of undici', async () => { | ||
expect(await quote()).toEqual({ | ||
quote: 'Life is what happens to you while you\'re busy making other plans.', | ||
author: 'John Lennon', | ||
}) | ||
}) | ||
|
||
test('should use a mocked implementation of sample', () => { | ||
expect(boolean()).toBe(false) | ||
}) |
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,5 +1,13 @@ | ||
import { main } from 'sample' | ||
import { request } from 'undici' | ||
|
||
export function app() { | ||
export async function quote() { | ||
const { body } = await request('https://dummyjson.com/quotes/7') | ||
const { quote, author } = await body.json() | ||
|
||
return { quote, author } | ||
} | ||
|
||
export function boolean() { | ||
return main() | ||
} |
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,4 @@ | ||
export function main() { | ||
console.log('Real implementation') | ||
console.log('sample: real implementation') | ||
return true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.