help-me-mom / ng-mocks

Angular testing library for mocking components, directives, pipes, services and facilitating TestBed setup
https://www.npmjs.com/package/ng-mocks
MIT License
1.05k stars 76 forks source link

Bug? Cannot combine @Input decorators with query decorators #181

Closed appienvanveen closed 4 years ago

appienvanveen commented 4 years ago

Hi,

im using your lib version 10.1.2 with angular 9.1.2 in combination with the Syncfusion angular framework.

I'm getting the following error when I run my tests: `

Error: Cannot combine @Input decorators with query decorators
    at http://localhost:9876/_karma_webpack_/D:/Work/Java

`

Code looks like follows:

describe('XComponent', () => {
    let component: XComponent;
    let fixture: MockedComponentFixture<XComponent>;
    beforeEach(() => MockBuilder(XComponent, XModule)
        .provide({provide: ControlContainer, useValue: fgd}),
    );
    beforeEach(() => {
        fixture = MockRender(XComponent);
        component = fixture.point.componentInstance;
        fixture.detectChanges();
    });
    it('should create', () => {
        expect(component).toBeTruthy();
        expect(component.controlContainer).toBeDefined();
    });
});

I'm not sure if this is caused by the mock framework or by the syncfusion library. Running the project works fine; even as building the project. This just happens when running the tests.

satanTime commented 4 years ago

Hi again,

might you share code of XComponent, or create a min code sample with the failing test?

appienvanveen commented 4 years ago

example-bug.zip

Please find a sample project attached :)

appienvanveen commented 4 years ago

Any idea yet? @satanTime :)

satanTime commented 4 years ago

Hi, unfortunately, didn't check it yet. I'll do that latest on Sunday evening. Sorry for the delay.

appienvanveen commented 4 years ago

No problem, take your time :)

appienvanveen commented 4 years ago

Any update yet? :)

satanTime commented 4 years ago

Checking :)

satanTime commented 4 years ago

Hi, I'm investigating it deeper, I have a fix, but I want to find the cause.

appienvanveen commented 4 years ago

Ah cool. I was thinking it was caused by the syncfusion library, but since it only occurse during testing/mocking I doubted this.

satanTime commented 4 years ago

Yep, the way they are creating components and directives in the lib causes the issue, they use decorators in an interesting manner, but if I do a copy for testing it doesn't fail anymore. So I'll try to dig deeper for understanding of the exact cause.

appienvanveen commented 4 years ago

Hi, it appears that when i disable ivy for the test in my tsconfig, the tests run fine.

satanTime commented 4 years ago

Ah, that's an awesome hint! Thanks, I'll try this way.

satanTime commented 4 years ago

Hi again, might you check if it solves your issue? ng-mocks.zip

appienvanveen commented 4 years ago

Works like a charm!

satanTime commented 4 years ago

Thanks for checking, I'll release the changes this week.

satanTime commented 4 years ago

A new version has been released. Thanks for the report.