-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
104 additions
and
84 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
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,20 @@ | ||
import {jest} from '@jest/globals'; | ||
|
||
|
||
declare type Model = Record<string, unknown>; | ||
declare type RenderFn = ( | ||
_view: string, | ||
_model: Model, | ||
_options: Record<string, unknown> | ||
) => Model; | ||
|
||
|
||
jest.mock('/lib/thymeleaf', () => ({ | ||
render: jest.fn<RenderFn>().mockImplementation(( | ||
_view, | ||
model, | ||
// options | ||
) => { | ||
return model; // Not testing the actual rendering, just that the model is correct. | ||
}) | ||
}), { virtual: true }); |
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,54 @@ | ||
import type { | ||
assetUrl as assetUrlType, | ||
getContent as getContentType, | ||
imageUrl as imageUrlType, | ||
} from '@enonic-types/lib-portal'; | ||
|
||
|
||
import { | ||
App, | ||
LibContent, | ||
LibPortal, | ||
Server | ||
} from '@enonic/mock-xp'; | ||
import {jest} from '@jest/globals'; | ||
|
||
|
||
export { | ||
Request, | ||
} from '@enonic/mock-xp'; | ||
|
||
|
||
const APP_KEY = 'com.example.tutorial.jest'; | ||
const PROJECT_NAME = 'intro'; | ||
|
||
|
||
export const server = new Server({ | ||
loglevel: 'debug' | ||
}).createProject({ | ||
projectName: PROJECT_NAME | ||
}).setContext({ | ||
projectName: PROJECT_NAME | ||
}); | ||
|
||
const app = new App({ | ||
key: APP_KEY | ||
}); | ||
|
||
export const libContent = new LibContent({ | ||
server | ||
}); | ||
|
||
export const libPortal = new LibPortal({ | ||
app, | ||
server | ||
}); | ||
|
||
|
||
jest.mock('/lib/xp/portal', () => { | ||
return { | ||
assetUrl: jest.fn<typeof assetUrlType>((params) => libPortal.assetUrl(params)), | ||
getContent: jest.fn<typeof getContentType>(() => libPortal.getContent()), | ||
imageUrl: jest.fn<typeof imageUrlType>((params) => libPortal.imageUrl(params)), | ||
} | ||
}, { virtual: true }); |