Giter VIP home page Giter VIP logo

angular-testing-techniques's Introduction

Angular Testing Techniques

This is a simple example to demonstrate various techniques to test Angular apps, specifically:

  1. Visualizing different states of a component using Storybook
  2. Unit testing a component
  3. Integration testing (a.k.a. end-to-end testing) the entire app
  4. Screenshot testing (a.k.a. visual regression testing) the entire app

A screenshot of the final app is shown below. It contains a single page with two tiles representing a buy order and a sell order in the stock market. Each tile is created using an Angular component called OrderViewComponent.

Screen Shot

This project was generated with Angular CLI version 6.0.8.

Quick Start

$ yarn install  <--- npm install works too
$ ng serve

Now point your browser to http://localhost:4200/.

Visualize component states

Allows you to visualize different states of your UI components and develop them interactively.

Tools

Tests

  • index.stories.ts: Instantiates the OrderViewComponent in five different states to ensure that it is rendered correctly.

Running the tests

yarn storybook

Point your browser to http://localhost:6006/

Unit testing

Tests a single component in isolation.

Tools

Tests

  • order-progress-bar.component.spec.ts: Instantiates the OrderProgressBarComponent in different states and tests if the bars in the progress bar have the expected lengths.

  • order-view.component.spec.ts: Instantiates the OrderViewComponent with a buy and a sell order and tests if the correct data and colors are rendered.

Running the tests

ng test

Integration (end-to-end) testing

Tests an entire app with multiple components, pages and navigation, while fully integrated with its back-end.

Tools

Tests

  • app.e2e-spec.ts: Navigates to the home page and tests if it renders two orders for the correct stocks. Uses a Page Object for low level page operations.

Running the tests

ng e2e

Screenshot (visual regression) testing

Compares current images of an app with previous images, and reports the differences

Tools

Tests

  • home-page.test.js: Takes a screenshot of the home page and compares it with its previously stored image. If the images don't match, the test fails and the difference in the images is saved under snapshot-testing/__image_snapshots__/__diff_output__. Try it by changing some code. For example, in order-view.component.css, change the color of .title--buy to yellow:
.title--buy {
    color: #f2d200;
}

Running the tests

yarn screenshot-test

angular-testing-techniques's People

Contributors

nareshbhatia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sss-software

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.