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

Visual Regression in Angular

Visual Regression in Angular

Visual Regression is about ensuring that the components always look as specified. A screenshot is taken and acts as future reference. In this talk, I demonstrate how to do that in Angular with the help of Storybook.

The source code is available on https://github.com/rainerhahnekamp/visual-regression-angular. The recording of the talk can be found on https://www.youtube.com/watch?v=RvOdxy4B3Lw

Rainer Hahnekamp

March 05, 2021
Tweet

More Decks by Rainer Hahnekamp

Other Decks in Programming

Transcript

  1. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Visual Regression Angular Meetup

    Graz, 4.3.2021 Rainer Hahnekamp https://www.youtube.com/watch?v=RvOdxy4B3Lw https://github.com/rainerhahnekamp/visual-regression-angular
  2. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp About me... • Rainer

    Hahnekamp • Trainer & Consultant for Angular • Full-Stack Developer @RainerHahnekamp
  3. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Puppetteer • Headless Browser

    • Special Jest Configuration required ◦ No TestBed ◦ Completely isolated from application • Can run in debug mode • PlayWright as upcoming competitor
  4. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp 2 Headless Browser Test

    Specs 1 3 4 Storybook Application Code (Components)
  5. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Storybook • Allows to

    isolate Components • Not Angular Specific • Configure a Component for various states • Can also used for visual widget library (not just testing)
  6. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Storybook Setup - "Module"

    Configuration - 1/3 export default { title: 'Eternal/HolidayCard', component: HolidayCardComponent, decorators: [moduleMetadata({ imports: [MatButtonModule, MatCardModule] })], argTypes: { holiday: { name: 'Holiday', description: 'JSON object for the Holiday' } } } as Meta;
  7. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Storybook Setup - Template

    - 2/3 const Template: Story<HolidayCardComponent> = (args: HolidayCardComponent) => ({ component: HolidayCardComponent, props: args });
  8. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Storybook Setup - Variation

    - 3/3 export const Default = Template.bind({}); Default.args = { holiday: { id: 1, title: 'Holiday', description: 'A holiday', imageUrl: 'https://eternal-app.s3.eu-central-1.amazonaws.com/assets/AngkorWatSmall.jpg' } };
  9. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp 2 Headless Browser Test

    Specs 1 3 4 Storybook Application Code (Components)
  10. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Towards a Testable Architecture

    • Level 1 - Atomic ◦ Unit Tests for Container Components, Services, Functions,... ◦ Visual Regression ◦ RxJS Marbles • Level 2 - Logical Groups ◦ Interplay between Container & Presentational Components ◦ Complex Components (DataGrid) ◦ State Management • Level 3 ◦ E2E Tests
  11. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Testable Architecture Level 1

    - Atomic Container Components Presentational Components State Management Domain Models Visual Regression Unit Tests
  12. Angular Meetup Graz, 4.3.2021 Rainer Hahnekamp Presentational Component • Easy

    to setup in Storybook • Decoupled from business logic • No Dependency Injection • If possible only primitive types as @Input