Skip to content

Angular 1 unit tests fail with Angular 2 components using downgradeComponents #14263

Closed

Description

@Rhathe

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

We are using the current documented way of downgrading Angular 2 components with the UpgradeModule for use in an Angular 1 hybrid app, specifically an angular 1 component. We have unit tests that uses $compile to create an element with our angular 1 component which itself uses a downgraded angular 2 component, which is downgraded with downgradeComponent in the static upgrade as opposed to the one in UpgradeAdapter. This works with interacting with the app in the browser. However, an error pops up in the unit test that says Error: [$injector:unpr] Unknown Provider $$angularInjectorProvider.

The error was previous documented here:
http://stackoverflow.com/questions/41128236/angular-2-unknown-provider-angularinjectorprovider-when-unit-testing-with

A possible hacky solution here was to call beforeEach(angular.mock.module('$$UpgradeModule')). While the error is gone, the unit tests still fail because changes are not being detected in the downgraded angular 2 component.

There seems to a fix in 2fc0560 that fixed the issue in #5462, but that is for the UpgradeAdapter and not for UpgradeModule.

Expected behavior

Existing angular 1 unit tests should be able to test angular 1 components that have angular 2 downgraded components without failing.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Angular version: 2.0.X
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]

  • Node (for AoT issues): node --version =

Activity

  1. jwoos commented on Feb 3, 2017

    @jwoos

    I have also experienced this issue

  2. sshev commented on Feb 7, 2017

    @sshev

    I have the same problem when trying to unit test ng1 services that have ng2 dependencies registered with downgradeInjectable()
    have to mock such ng2 dependencies in order to make existing tests pass, which makes migration from ng1 to ng2 more painful

  3. dkanev commented on Feb 7, 2017

    @dkanev

    +1

  4. ronwang01 commented on Feb 14, 2017

    @ronwang01

    +1

  5. djpark commented on Feb 15, 2017

    @djpark

    +1

  6. idoglik6 commented on Mar 1, 2017

    @idoglik6

    +1

  7. bh86 commented on Mar 1, 2017

    @bh86

    +1

  8. ninaneter commented on Mar 1, 2017

    @ninaneter

    +1

  9. moanrose commented on Mar 13, 2017

    @moanrose

    +1

  10. amosuro commented on May 12, 2017

    @amosuro

    +1 the documentation is great but this issue is making the idea of gradually migrating to Angular very difficult.

  11. nikolay-lesko commented on May 15, 2017

    @nikolay-lesko

    +1

  12. gkalpak commented on Jul 4, 2017

    @gkalpak
    Member

    For the time being, the simplest approach is to bootstrap a "mini hybrid app" for each test (which is less than ideal for several reasons). Testing with ngUpgrade will be improved much once #16848 is merged 😃

  13. gkalpak commented on Dec 15, 2017

    @gkalpak
    Member

    I am going to close this. Let's track the addition of test helpers for ngUpgrade in #16848.

  14. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  15. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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