Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FrontEnd Test Night - Fukuoka #1

puku0x
March 05, 2019

FrontEnd Test Night - Fukuoka #1

puku0x

March 05, 2019
Tweet

More Decks by puku0x

Other Decks in Technology

Transcript

  1. Angular A platform for building modern Web Apps • Move

    faster • Scale better • Reach further https://angular.io/ 6
  2. Generating a component $ ng generate component sample CREATE src/app/sample/sample.component.scss

    (0 bytes) CREATE src/app/sample/sample.component.html (23 bytes) CREATE src/app/sample/sample.component.spec.ts (614 bytes) CREATE src/app/sample/home.component.ts (262 bytes) UPDATE src/app/app.module.ts (467 bytes) 8
  3. Generating a service $ ng generate service api CREATE src/app/api.service.spec.ts

    (323 bytes) CREATE src/app/api.service.ts (133 bytes) 9
  4. Creating an app $ ng new my-app --routing --style=scss CREATE

    my-app/angular.json (3895 bytes) CREATE my-app/package.json (1389 bytes) CREATE my-app/src/karma.conf.js (1019 bytes) CREATE my-app/src/tsconfig.spec.json (256 bytes) CREATE my-app/e2e/protractor.conf.js (752 bytes) CREATE my-app/e2e/tsconfig.e2e.json (213 bytes) CREATE my-app/src/main.ts (372 bytes) ... 13
  5. describe('SampleComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [

    SampleComponent ] }).compileComponents(); })); it('should create', () => { fixture = TestBed.createComponent(SampleComponent); component = fixture.componentInstance; expect(component).toBeTruthy(); }); }); 15
  6. import { NO_ERRORS_SCHEMA } from '@angular/core'; describe('SomeComplexComponent', () => {

    beforeEach(async(() => { TestBed.configureTestingModule({ ... schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); })); }); 16
  7. describe('ApiService', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [

    HttpClientTestingModule ] }); service = TestBed.get(ApiService); }); it('should be created', () => { expect(service).toBeTruthy(); }); }); 17
  8. import { HttpTestingController } from '@angular/common/http/testing'; describe('UserService', () => {

    beforeEach(() => { ... httpMock = TestBed.get(HttpTestingController); }); afterEach(() => httpMock.verify()); it('should successfully mock request', () => { const response = {...}; service.fetch().subscribe(result => expect(result).toBe(response)); const req = httpMock.expectOne(`/api/v1/samples`); expect(req.request.method).toEqual('GET'); req.flush(response); }); }); 18
  9. import { browser, by, element } from 'protractor'; describe('App', ()

    => { it('should display title', () => { browser.get('/'); const title = element(by.css('h1')).getText(); expect(title).toEqual('Hello Angular!'); }); }); 20
  10. describe('AppComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [AppComponent]

    }).compileComponents(); })); test('should match to snapshot', () => { const fixture = TestBed.createComponent(AppComponent); expect(fixture).toMatchSnapshot(); }); }); 23
  11. 25

  12. 26