-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(validation): add failing slug test; configure jest
- Loading branch information
1 parent
9062b84
commit 9522cc9
Showing
5 changed files
with
150 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const path = require('path') | ||
|
||
/** @type {import('@jest/types').Config.InitialOptions} */ | ||
const config = { | ||
verbose: true, | ||
moduleNameMapper: { | ||
'@sanity/validation': path.resolve(__dirname, './src'), | ||
'part:@sanity/base/schema-creator': path.resolve(__dirname, '../base/lib/schema/createSchema'), | ||
'part:@sanity/form-builder/input/legacy-date/schema?': path.resolve( | ||
__dirname, | ||
'./test/nullExport' | ||
), | ||
'part:@sanity/base/client': path.resolve(__dirname, './test/mockClient'), | ||
}, | ||
} | ||
|
||
module.exports = config |
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 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,37 @@ | ||
import type {SanityClient} from '@sanity/client' | ||
|
||
/** | ||
* this mock client is used via the `moduleNameMapper` in `jest.config.js` | ||
* | ||
* you can import the part and use the mock from each method like so: | ||
* | ||
* ```ts | ||
* import client from 'part:@sanity/base/client' | ||
* | ||
* afterEach(() => { | ||
* ;(client.fetch as jest.Mock).mockReset(); | ||
* }) | ||
* | ||
* describe('someFeatureThatUsesTheClient', () => { | ||
* | ||
* test('some test', async () => { | ||
* // set up the mock | ||
* ;(client.fetch as jest.Mock).mockImplementation(() => Promise.resolve('example')) | ||
* | ||
* // do you test | ||
* // e.g. validateDocument() | ||
* | ||
* expect(client.fetch).toHaveBeenCalledTime(1) | ||
* expect((client.mock as jest.Mock).mock.calls).toMatchObject({ | ||
* // ... | ||
* }) | ||
* }) | ||
* }) | ||
* ``` | ||
*/ | ||
const client = ({ | ||
fetch: jest.fn(), | ||
withConfig: jest.fn(() => client), | ||
} as unknown) as SanityClient | ||
|
||
module.exports = client |
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 @@ | ||
// used to mock out a part | ||
// see the jest config | ||
module.exports = null |