Skip to content

New async(inject()) test pattern does not handle unresolved promises; no mention of work around #8736

@Yona-Appletree

Description

@Yona-Appletree

Steps to reproduce and a minimal demo of the problem

Write a test using async(inject()) (or the deprecated injectAsync) which returns a promise that is never fulfilled. Prior to #7735, the test would fail. It now passes.

See http://plnkr.co/edit/FTEe8DmlZGmFDQBDqcrv?p=preview for a trivial example of a test that should fail, but passes.

Current behavior

The given way of testing asynchronous code, async(inject()) and by extension, injectAsync, does not (and does not seem provide a way to) ensure that a test promise is completed.

Expected/desired behavior

A built-in method to ensure that a test will only pass if a particular promise is resolved. Perhaps simply by bringing back the old functionality of injectAsync and renaming it to something else.

Additionally, the change log (https://github.com/angular/angular/blob/master/CHANGELOG.md) should mention this important and breaking change (it does mention injectAsync -> async(inject()), but not the substantial change in behavior).

Other information

We have a number (~50) tests that rely the behavior of returning a promise that should resolve, or the test fails. After we upgraded to beta17, we started seeing false successes on tests. This mostly occurred because our business logic would call the mock HTTP service, but not with the correct parameters (e.g. http method or path) and our mock response code would thusly not return a response. Since all async methods had completed at that point, the test would erroneously pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions