Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for RenderNgAppService
Configure app/angular package as jest projects Allow to use jest-preset-angular for app/angular tests
- Loading branch information
Showing
8 changed files
with
77 additions
and
3 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,4 @@ | ||
module.exports = { | ||
preset: 'jest-preset-angular', | ||
setupFilesAfterEnv: ['<rootDir>/setup-jest.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,2 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import 'jest-preset-angular'; |
52 changes: 52 additions & 0 deletions
52
app/angular/src/client/preview/angular/RenderNgAppService.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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Component } from '@angular/core'; | ||
import { platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
|
||
import { StoryFnAngularReturnType } from '../types'; | ||
import { RenderNgAppService } from './RenderNgAppService'; | ||
|
||
jest.mock('@angular/platform-browser-dynamic'); | ||
|
||
declare const document: Document; | ||
describe('RenderNgAppService', () => { | ||
let renderNgAppService: RenderNgAppService; | ||
|
||
beforeEach(async () => { | ||
document.body.innerHTML = '<div id="root"></div>'; | ||
(platformBrowserDynamic as any).mockImplementation(platformBrowserDynamicTesting); | ||
renderNgAppService = new RenderNgAppService(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should initialize', () => { | ||
expect(renderNgAppService).toBeDefined(); | ||
}); | ||
|
||
it('should add storybook-wrapper for story template', async () => { | ||
await renderNgAppService.render( | ||
(): StoryFnAngularReturnType => ({ template: '🦊', props: {} }), | ||
false | ||
); | ||
|
||
expect(document.body.innerHTML).toBe( | ||
'<div id="root"><storybook-wrapper ng-version="11.0.0">🦊</storybook-wrapper></div>' | ||
); | ||
}); | ||
|
||
it('should add storybook-wrapper for story component', async () => { | ||
@Component({ selector: 'foo', template: '🦊' }) | ||
class FooComponent {} | ||
|
||
await renderNgAppService.render( | ||
(): StoryFnAngularReturnType => ({ component: FooComponent, props: {} }), | ||
false | ||
); | ||
|
||
expect(document.body.innerHTML).toBe( | ||
'<div id="root"><storybook-wrapper ng-version="11.0.0"><foo>🦊</foo></storybook-wrapper></div>' | ||
); | ||
}); | ||
}); |
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,9 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["webpack-env", "jest", "node"], | ||
"typeRoots": ["../../node_modules/@types", "node_modules/@types"], | ||
"allowJs": true | ||
}, | ||
"include": ["**/*.test.ts", "**/*.d.ts", "setup-jest.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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"**/node_modules", | ||
"**/*.spec.ts", | ||
"**/__tests__", | ||
"**/*.test.ts" | ||
"**/*.test.ts", | ||
"**/setup-jest.ts" | ||
] | ||
} |