You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test injector should work smoothly with new bundles #5351
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
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.
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?
@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.
Activity
juliemr commentedon Dec 12, 2015
The default should be the same thing that you get with
bootstrap- ready for use in the browser and with platform directives set up.juliemr commentedon Dec 17, 2015
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_PROVIDERSandTEST_<PLATFORM>_APPLICATION_PROVIDERS.The test injector, and by extension
angular2/testing, will export asetBaseTestProvidersfunction. 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 intest-main.jswill change.Breaking changes: This is a breaking change for tests, because of the change to the setup function.
In-progress CL coming soon!
juliemr commentedon Dec 17, 2015
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.
cexbrayat commentedon Dec 17, 2015
I hope you don't mind, I have 2 questions.
I scrolled through your PR and I couldn't figure if the
COMMON_DIRECTIVESandCOMMON_PIPESwould be included inTEST_BROWSER_PLATFORM_PROVIDERSorTEST_BROWSER_APPLICATION_PROVIDERS?I was also wondering if it was considered to include something for the
EVENT_MANAGER_PLUGINS, to get rid ofprovide(EVENT_MANAGER_PLUGINS, {useClass: KeyEventsPlugin, multi: true})in tests?juliemr commentedon Dec 17, 2015
@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.cexbrayat commentedon Dec 17, 2015
Ha great, that was the bit I missed! Thx @juliemr , I look forward to test this.
6 remaining items
jonnysamps commentedon Jan 29, 2016
Looks like the exports for
TEST_BROWSER_PLATFORM_PROVIDERSandTEST_BROWSER_APPLICATION_PROVIDERSdidn't make it into the bundles. Is this on purpose?ericmartinezr commentedon Jan 29, 2016
@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
jonnysamps commentedon Jan 29, 2016
Good tip @ericmartinezr! Thanks
angular-automatic-lock-bot commentedon Sep 7, 2019
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.