Skip to content

test injector should work smoothly with new bundles #5351

Closed

Description

@juliemr

With the new platform bundles, you can import directly from what you need for different platforms:

import {bootstrap} from {'angular2/platform/browser'};

However, the test injector is currently hardwired to only work for the browser platform. We need a smooth way of writing unit tests with an injector for a different platform. cc @vsavkin

Activity

  1. added
    area: testingIssues related to Angular testing features, such as TestBed
    on Nov 17, 2015
  2. self-assigned this
    on Nov 17, 2015
  3. added this to the milestone on Nov 30, 2015
  4. juliemr commented on Dec 12, 2015

    @juliemr
    ContributorAuthor

    The default should be the same thing that you get with bootstrap - ready for use in the browser and with platform directives set up.

  5. juliemr commented on Dec 17, 2015

    @juliemr
    ContributorAuthor

    Proposal:

    Just like an application, Angular2 unit tests are going to need a bootstrap which will vary depending on the platform they are written for. Let's mirror the method of exporting different lists of providers by platform for tests as well, and export a setup function. These will live in modules/angular2/platform/testing/*.ts.

    A new injector is created for each test case. We'll export suggested testing platform and application providers for each platform. Name them TEST_<PLATFORM>_PLATFORM_PROVIDERS and TEST_<PLATFORM>_APPLICATION_PROVIDERS.

    The test injector, and by extension angular2/testing, will export a setBaseTestProviders function. This will need to be called by the test framework before any tests are run. This is not a huge burden because we already required some initialization - to set up the current dom adapter - which will be replaced. For example, in Angular's internal test suite the setup in test-main.js will change.

    Breaking changes: This is a breaking change for tests, because of the change to the setup function.

    In-progress CL coming soon!

  6. juliemr commented on Dec 17, 2015

    @juliemr
    ContributorAuthor

    Design CL: #5975

    There's still some clean-up to do, but it's a working prototype. cc @IgorMinar @alxhub @pkozlowski-opensource for design thoughts.

  7. cexbrayat commented on Dec 17, 2015

    @cexbrayat
    Member

    I hope you don't mind, I have 2 questions.

    I scrolled through your PR and I couldn't figure if the COMMON_DIRECTIVES and COMMON_PIPES would be included in TEST_BROWSER_PLATFORM_PROVIDERS or TEST_BROWSER_APPLICATION_PROVIDERS?

    I was also wondering if it was considered to include something for the EVENT_MANAGER_PLUGINS, to get rid of provide(EVENT_MANAGER_PLUGINS, {useClass: KeyEventsPlugin, multi: true}) in tests?

  8. juliemr commented on Dec 17, 2015

    @juliemr
    ContributorAuthor

    @cexbrayat yes, these things are all included. TEST_BROWSER_APPLICATION_PROVIDERS => BROWSER_APP_PROVIDERS => BROWSER_APP_COMMON_PROVIDERS (here) which includes common directives, common pipes, and event manager plugins.

  9. cexbrayat commented on Dec 17, 2015

    @cexbrayat
    Member

    Ha great, that was the bit I missed! Thx @juliemr , I look forward to test this.

  10. 6 remaining items

  11. jonnysamps commented on Jan 29, 2016

    @jonnysamps

    Looks like the exports for TEST_BROWSER_PLATFORM_PROVIDERS and TEST_BROWSER_APPLICATION_PROVIDERS didn't make it into the bundles. Is this on purpose?

  12. ericmartinezr commented on Jan 29, 2016

    @ericmartinezr
    Contributor

    @jonnysamps saw the same today. I modify @brandonroberts plnkr and added manually everything needed http://plnkr.co/edit/mHx5yXmvnwpaf0ZICJ7l?p=info (skip everything on the top, you'll freak out). Hopefully for beta.3 this will be easier :D

  13. jonnysamps commented on Jan 29, 2016

    @jonnysamps

    Good tip @ericmartinezr! Thanks

  14. angular-automatic-lock-bot commented on Sep 7, 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 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions