Slide 1

Slide 1 text

@RainerHahnekamp Rainer Hahnekamp 22. Februar 2023 Cypress Component Tests Revolution des Testens?

Slide 2

Slide 2 text

@RainerHahnekamp About Me... Rainer Hahnekamp https://www.twitter.com/RainerHahnekamp Professional NgRx https://www.youtube.com/@RainerHahnekamp https://www.youtube.com/@ng-news

Slide 3

Slide 3 text

@RainerHahnekamp Agenda ● Testing Strategies in SPAs ● Testing in Angular currently ● Cypress Component Testing ○ Simple Tests ○ Various Use Cases ● Q&A Caution: Live Coding Ahead

Slide 4

Slide 4 text

@RainerHahnekamp Testing in Angular Unit Tests Integration & Component Tests End-to-End (E2E) Tests

Slide 5

Slide 5 text

@RainerHahnekamp Disadvantages of Testing Types Unit ● Low Coverage ● High Maintenance Costs ● Ignores UI Component / Integration ● Complex TestBed setup ● DOM interaction is hard ● Change Detection End-to-End ● Slow ● Hard to setup

Slide 6

Slide 6 text

@RainerHahnekamp Classic testing pyramide Unit Tests Integration & Component Tests End-to-End (E2E) Tests

Slide 7

Slide 7 text

@RainerHahnekamp Testing pyramide with Cypress Component Test Runner Unit Tests Integration & Component Tests End-to-End (E2E) Tests

Slide 8

Slide 8 text

@RainerHahnekamp Integration/Component vs. E2E Tests Integration/Component Tests ✅ Test components in isolation ✅ Precision & Control ✅ Fast ⛔ TestBed Setup ⛔ Manage asynchrony ⛔ Manage change detection ⛔ "DOM interaction" E2E Tests ✅ No asynchrony management ✅ No change detection management ✅ Developer experience - Browser feedback - Screenshots - Video recording - Tasks, network stubbing,... ⛔ Infrastructure setup required ⛔ Slow

Slide 9

Slide 9 text

@RainerHahnekamp Component/Integration in Cypress ✅ Test components in isolation ✅ Precision & Control ✅ No asynchrony management ✅ No change detection management ✅ Developer experience ⛔ TestBed Setup ⛔ Speed???

Slide 10

Slide 10 text

@RainerHahnekamp

Slide 11

Slide 11 text

@RainerHahnekamp RequestInfo MatFormFieldModule FormBuilder AddressLookuper ReactiveFormsModule MatIconModule MatButtonModule MatInputModule NgIf AsyncPipe ActivatedRoute HolidaysRepository HttpClient HolidaysEffects HolidayCard MatCardModule MatButtonModule RouterLink

Slide 12

Slide 12 text

@RainerHahnekamp Coding Time

Slide 13

Slide 13 text

@RainerHahnekamp Test Cases ● Basic Testing ● Network Interception ○ Intercept ○ Verify ● Wrapper Component ● Accessing DI ● A11n Selectors

Slide 14

Slide 14 text

@RainerHahnekamp Agenda Component & Integration Tests ● Styling ● Mocking Services ● Mocking Components ● Asynchrony Management ● Accessing DI Component Inter-Communication ● Spy on @Output ● Setting @Input ● WrapperComponent Cypress Ecosystem ● Different Screen Sizes ● Actionability ● cy.intercept ● Cypress Commands ● Testing Library ● Code Coverage

Slide 15

Slide 15 text

@RainerHahnekamp Is there only Cypress?

Slide 16

Slide 16 text

@RainerHahnekamp Summary ● Cypress component testing ○ is much easier to write & maintain ○ discovers more visual bugs ○ starts a new era of testing ● Performance penalties neglectable ● Jest/Karma will still be used for unit tests ○ Look out for Vitest

Slide 17

Slide 17 text

@RainerHahnekamp Thanks!!!

Slide 18

Slide 18 text

@RainerHahnekamp Contact: Rainer Hahnekamp @Rainer Hahnekamp https://www.youtube.com/@RainerHahnekamp https://www.youtube.com/@ng-news https://www.angulararchitects.io https://www.rainerhahnekamp.com