Skip to content

Instantly share code, notes, and snippets.

View test
it('should call SampleContainerComponent.submitAction()', () => {
jest.spyOn(container, 'submitAction');
// 子Componentのemit
(fixture.debugElement.query(By.directive(SampleComponent)).componentInstance as SampleComponent).submitAction.emit();
// 親Containerのmethodがcallされてるかテスト
expect(container.submitAction).toHaveBeenCalledWith();
})
View beforeach
beforeEach(async () => {
TestBed.configureTestingModule({
// 親Container, 子Component
declarations: [SampleContainerComponent, SampleComponent],
});
await TestBed.compileComponents();
});
View fetch
fetch('https://hoge.com/users/1', {method: 'GET'})
View environement.ts
import '../mocks/browser'; // add code
export const environment = {
production: false,
};
View browser.js
import { setupWorker, rest } from 'msw'
export const mocks = [
rest.get('https://hoge.com/users/:user', (req, res, ctx) => {
const { user } = req.params
return res(
ctx.status(200),
ctx.json({
name: `mocked-${user}`,
View init
// 例(myorgは自分のアプリ名)
npx msw init apps/myorg/src
View msw install
npm install msw --save-dev
# or
yarn add msw --dev
View update config
// appNameは自分のアプリ名
nx g nx-ng-esbuild:add-esbuild-config appName
View install
yarn add -D nx-ng-esbuild
View app.module.ts
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
@NgModule({
declarations: [
StoreModule.forRoot({ LoginState: loginReducer}), // LoginStateはselectorで書いたキー
EffectsModule.forRoot([LoginEffects]),
],