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

Jest, the boost for the Angular Testing Platform

Jest, the boost for the Angular Testing Platform

As long as your tests are green, everything is fine, right? The inconveniences will always come up when a test is red.
Which tests are affected? Why is the test failing now?

Often, this research involves reading obscure console editions that take up your time and nerves.
Most of the time you can wait a while until all your tests have gone through to know if the alleged fix really solves the problem.

Jest replaces long waiting times with instant feedback. Instead of cryptic error logs, you will receive targeted information to help you solve the problem.

This talk demonstrates how to install & use Jest in your Angular project. You will be introduced to the integrated mocking framework and snapshot testing in detail.
Then you know the benefits that Jest offers. In addition, you have a blueprint to start immediately with Jest.

https://medium.com/@gregor.woiwode
https://twitter.com/GregOnNet

Gregor Woiwode

April 02, 2019
Tweet

More Decks by Gregor Woiwode

Other Decks in Programming

Transcript

  1. Background START - maintains Jest - Jasmine is used under

    the hood - Git is used to improve test runs - Open Source
  2. it.each REPITITION DONE RIGHT it.each([['.huskyrc.json'], ['.huskyrc.js']])( ' should warn if

    detected in %s', (file: string) => { project.create(file, JSON.stringify({})); runner.runSchematic('prettier', {}, project); expect(warn).toHaveBeenCalledWith( `Found competing husky configuration in ${file}.` ); });
  3. it.each REPITITION DONE RIGHT it.each([['.huskyrc.json'], ['.huskyrc.js']])( ' should warn if

    detected in %s', (file: string) => { project.create(file, JSON.stringify({})); runner.runSchematic('prettier', {}, project); expect(warn).toHaveBeenCalledWith( `Found competing husky configuration in ${file}.` ); });
  4. it.each REPITITION DONE RIGHT it.each([['.huskyrc.json'], ['.huskyrc.js']])( ' should warn if

    detected in %s', (file: string) => { project.create(file, JSON.stringify({})); runner.runSchematic('prettier', {}, project); expect(warn).toHaveBeenCalledWith( `Found competing husky configuration in ${file}.` ); });
  5. it.each`` REPITITION DONE RIGHT it.each` compilerOption | expected ${'strict‘} |

    ${true} ${'noUnusedParameters'} | ${true} ${'noUnusedLocals‘} | ${true} ${'noImplicitAny‘} | ${true} ` ( 'should set $compilerOption to default value of schema ($expected)‘, ({ compilerOption, expected }) => { // ... expect(tsconfig.compilerOptions[option]).toBe(expected); } );
  6. it.each`` it.each` compilerOption | expected ${'strict‘} | ${true} ${'noUnusedParameters'} |

    ${true} ${'noUnusedLocals‘} | ${true} ${'noImplicitAny‘} | ${true} ` ( 'should set $compilerOption to default value of schema ($expected)‘, ({ compilerOption, expected }) => { // ... expect(tsconfig.compilerOptions[option]).toBe(expected); } ); REPITITION DONE RIGHT
  7. Anathomy SNAPSHOT TESTING exports[`<app-root> When the application starts displays the

    welcome message 1`] = ` <p> Welcome to the playground, you will find all testing samples in <code>*.spec.ts</code> files. </p> `; __snapshots__/*.spec.ts.snap
  8. Anathomy SNAPSHOT TESTING exports[`<app-root> When the application starts displays the

    welcome message 1`] = ` <p> Welcome to the playground, you will find all testing samples in <code>*.spec.ts</code> files. </p> `; __snapshots__/*.spec.ts.snap
  9. … really everything AUTOMATE EVERYTHING ng generate @co-it/schematics:jest ng generate

    @co-it/schematics:commitlint ng generate @co-it/schematics:cypress ng generate @co-it/schematics:tsconfig ng generate @co-it/schematics:prettier
  10. Summary JEST it.each simplify generation of test cases jest.fn is

    used for mocking depencencies expect.??? contains usefule additions @co-IT/schematics configure Jest automatically
  11. co-IT.eu GmbH Inspire To Change @GregOnNet Thank you for listening

    @co-it/schematics https://github.com/GregOnNet/jest-playground
  12. Images & Icons CREDITS - , , made by Freepik

    from flaticon.com - Photos by - Jakob Owens - Andreas Wagner - Shiro hatori - Josue Valencia - Jonathan Chng - on Unsplash