New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestBed passes even without any declarations in NG9 and NG10 #38600
Comments
I believe that Issue #38373 may also be related to this regression, which I guess could have been caused when the cached dependencies in tests feature was added. |
Hi @smzelek, Thanks for providing an example that illustrates the setup of the described use-case. This is indeed a known difference between View Engine and Ivy - in View Engine, components are compiled in the context of some environment - either a platform browser instance, or a test. Therefore each test must declare its own testing module and import what it wants to compile. In Ivy, there is only one compiled version of a component at any time, and this compilation happens independently of the TestBed. Therefore Currently we are in a transition period where both View Engine and Ivy renderers exist in the codebase and are available to developers. In order to provide backwards compatibility for most common use-cases, we retained existing TestBed API semantics (which are designed around View Engine's behavior) and made it compatible with Ivy. Once View Engine is removed from the codebase, we plan to revisit the TestBed API and redesign it to better reflect Ivy semantics. Thank you. |
@AndrewKushnir Thank you for your detailed response! It would be great if there was any mention of this in https://angular.io/guide/testing-components-basics or...anywhere, I guess. Is this documented somewhere that I don't know? We couldn't find anything about it. Plus, I'm not sure you're right anyway. I have made another reproduction repo. When you run the app with Now, let's look at the tests. I have 3 tests in From your answer, one would expect all three tests to pass. This is not true. When you run them individually, Test 1 fails, Test 2 fails, and Test 3 passes. In another regression, none of these failing tests correctly complain about their missing dependencies. They successfully render the root component of the Test ( The real trouble comes when you run the tests together as a suite, because their pass/fail completely depends upon order, like so....
In short, this should not be tagged as "state: works-as-expected". This entire behavior is mystifying for a developer. |
`tView` that is stored on a component def contains information about directives and pipes that are avaiulable in the scope of this component. Patching component scope causes `tView` to be updated. Prior to this commit, the `tView` information was not restored/reset in case component class is not declared in the `declarations` field while calling `TestBed.configureTestingModule`, thus causing `tView` to be reused between tests (thus preserving scopes information between tests). This commit updates TestBed logic to preserve `tView` value before applying scope changes and reset it back to the previous state between tests. Closes angular#38600.
`tView` that is stored on a component def contains information about directives and pipes that are available in the scope of this component. Patching component scope causes `tView` to be updated. Prior to this commit, the `tView` information was not restored/reset in case component class is not declared in the `declarations` field while calling `TestBed.configureTestingModule`, thus causing `tView` to be reused between tests (thus preserving scopes information between tests). This commit updates TestBed logic to preserve `tView` value before applying scope changes and reset it back to the previous state between tests. Closes angular#38600.
`tView` that is stored on a component def contains information about directives and pipes that are available in the scope of this component. Patching component scope causes `tView` to be updated. Prior to this commit, the `tView` information was not restored/reset in case component class is not declared in the `declarations` field while calling `TestBed.configureTestingModule`, thus causing `tView` to be reused between tests (thus preserving scopes information between tests). This commit updates TestBed logic to preserve `tView` value before applying scope changes and reset it back to the previous state between tests. Closes angular#38600.
Hi @smzelek, Thanks for providing a new repro, the described scenario is not handled by Ivy TestBed and this is a bug. I performed additional investigation and found out that there is a piece of state that is preserved between tests in case a component is present in the You can also test the behavior using an updated version of the Thank you. |
Hi @AndrewKushnir, Sorry to jump in this because I need a bit help in understanding what Does it mean in Ivy, component compilation is done somewhere else before tests execute while It would be very appreciate for your help to explain a bit more about that. I am working for |
Hi @ahnpnl, Components might be pre-compiled (in AOT mode) before tests are executed by TestBed, in which case TestBed uses compiled components and only re-compile them (in JIT mode) when there is an override which can not be applied as a patch (i.e. without triggering a re-compilation), for example if a template is overwritten in a test. In View Engine's version of TestBed components were always re-compiled for each set of tests. Looking at the issue that you refer to (thymikee/jest-preset-angular#409), I think it might make sense to open a new ticket and describe questions/issues that you have, so that the team can provide some additional insights. Thank you. |
`tView` that is stored on a component def contains information about directives and pipes that are available in the scope of this component. Patching component scope causes `tView` to be updated. Prior to this commit, the `tView` information was not restored/reset in case component class is not declared in the `declarations` field while calling `TestBed.configureTestingModule`, thus causing `tView` to be reused between tests (thus preserving scopes information between tests). This commit updates TestBed logic to preserve `tView` value before applying scope changes and reset it back to the previous state between tests. Closes #38600. PR Close #38659
`tView` that is stored on a component def contains information about directives and pipes that are available in the scope of this component. Patching component scope causes `tView` to be updated. Prior to this commit, the `tView` information was not restored/reset in case component class is not declared in the `declarations` field while calling `TestBed.configureTestingModule`, thus causing `tView` to be reused between tests (thus preserving scopes information between tests). This commit updates TestBed logic to preserve `tView` value before applying scope changes and reset it back to the previous state between tests. Closes angular#38600. PR Close angular#38659
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
Affected Package
The issue seems to be in
@angular/core/testing
or the new bazel/ivy build rig.Is this a regression?
Yes, this behavior worked in Angular 8.
Angular 8 reports the following error...
Description
Angular's TestBed no longer works in any kind of logical way.
You can completely remove calls to
TestBed.configureTestingModule
and the unit tests still run, compile, and succeed. This is totally unexpected, as you are supposed to be able to pass declarations or mock declarations for every token. It's now completely unclear what environment is being used when the test runs, whereas before you explicitly provided every dependency.🔬 Minimal Reproduction
https://github.com/smzelek/minimal-repro-ng10-testbed-bug
Simply run the unit tests:
Notice that all 3 tests pass, the component is successfully rendered in the Karma runner window, variable templating succeeds..., even though there is no TestBed configuration at all.
🌍 Your Environment
Angular Version:
The text was updated successfully, but these errors were encountered: