Code Monkey home page Code Monkey logo

angular-async-test-specs's Introduction

Angular Asynchronous Test Specification

This workspace defines a test specification async.spec.ts which tests various asynchronous test scenarios common to Angular including handling micro and macrotasks with fakeAsync and ComponentFixture.whenStable, asynchronous RxJS functions and operators, and update behaviors of the Nimble Design System and the underlying @microsoft/fast-foundation components.

Usage

  • See async.spec.ts.
  • Run npm test to run and watch the tests.
  • Run npm test:ci to run the tests once.

Notes

The following are notes derived from these tests.

Micro and Macrotasks

RxJS

  • Asynchronous RxJS functions and operators, e.g. timer, delay, debounceTime, commonly use the AsyncScheduler which schedules periodic tasks with setInterval.
  • flush does not work with the AsyncScheduler. Therefore, tick or ComponentFixture.whenStable are commonly required for tests involving asynchronous RxJS operations.
  • Some of these functions accept a scheduler parameter that will override the default. However, schedulers like the AnimationFrameScheduler fallback to the AsyncScheduler for RxJS operations that require a timer.

Nimble Design System

  • fakeAsync may not work with even simple asynchronous Nimble updates like button appearance.
  • ComponentFixture.whenStable will commonly execute Nimble updates without issue, but waitForUpdatesAsync will not execute non-Nimble tasks.
  • Nimble can leak tasks between fakeAsync tests causing test failures due to pending queued tasks.
  • Nimble's waitForUpdatesAsync has two common issues.
    • In watch mode, waitForUpdatesAsync may timeout after a change and compile. Refresh the page to rerun the test.
    • non-fakeAsync tests can leak tasks that break calls to waitForUpdatesAsync for all subsequent tests.
  • There have been a few reported cases where ComponentFixture.whenStable did not work and waitForUpdatesAsync was required. However, the exact reason is not known.

angular-async-test-specs's People

Contributors

trevorkarjanis avatar

Watchers

 avatar

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.