-
Notifications
You must be signed in to change notification settings - Fork 100
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
Issue with Decorator when testing component #91
Comments
How do you expect us to help you if you don't provide any reproducible example? 🤔 🙂 |
Apologies. I cannot post real example so I was doing a mocking scenario to show you ;) Working Component and Test:
Not Working Component and Test (including Service as a provider for Component): Service:
Component:
Test NOT WORKING:
Running not working example it gives |
Sorry, I ain't able to reproduce it. This would be great if you'd have provided a reproducible example (git repo). |
okay, that is totally weird. this is the actual code i have while running which gives me this error. not sure what else i can do and how making a git repo going to help with that since its already not working for you |
Weird what? I don't have time to create the project manually, copy-paste that code and try to reproduce it locally. What I would like to see is a link to git repository and instructions:
This is normal policy. In most projects issues reported without a reproduction are closed immediately, e.g. if you open an issue in Angular's repository. Since I give of my personal time to work on these issues and I would rather be spending my time fixing issues than chasing down the unreproducible issue. 😉 |
Hey, I do understand it is hard for you to do it w/o reproducible scenario but I wouldn't continue previous ticket or open a new one if it was working =) It also kinda took some time to make a scenario to reproduce and now the project to run it gracefully. Anyways I am attaching zip with solution ... just npm i and than ng test to see the issue (it has exactly versions of angular 9 libs as the project I got this error in) |
Thanks for reproduction. I was able to reproduce it, this is clearly a bug. |
As i was saying it happens only in case you override component with injections having decorator. In case you unit test just service that is decorated, or just a component that is decorated but without providers - it works fine. Tried to also debug this if it is of any help and it seems that it actually fails on the component rather than service. Wild guess is that override component from test suite somehow removes decorator when you override - but needs more investigation |
Honestly saying don't know what to propose here. @NetanelBasal do you have any thoughts? |
You can invoke it manually: fdescribe('NotWorkingTestComponent', () => {
let component: NotWorkingTestComponent;
let fixture: ComponentFixture<NotWorkingTestComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [NotWorkingTestComponent],
})
.overrideComponent(NotWorkingTestComponent, {
set: {
providers: [{ provide: TestService, useClass: MockService }],
},
})
.compileComponents();
UntilDestroy()(NotWorkingTestComponent); <=======
fixture = TestBed.createComponent(NotWorkingTestComponent);
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
it('should create', () => {
fixture.detectChanges();
expect(component).toBeTruthy();
});
}); |
Thanks, it is a workable solution to overcome this issue! |
Hi, got same issue with spectator. Fixed with
|
I actually got same issue as the paradoxm in closed Issue #81
I have 1 unit test which doesnt raise this issue on the component which is decorated with UntilDestroy(). This component doesnt have any component level providers. Simple
And in another case it breaks with same error mentioned in the original ticket.
The only difference in two tests I noticed - it happens whenever you override components to inject component providers after TestBed.configureTestingModule({}) and before compileComponents().
In other words in case you have component decorated and you inject any providers component-level (services) it doesn't play nice
Originally posted by @f1ght4fun in #81 (comment)
The text was updated successfully, but these errors were encountered: