Closed mdv27 closed 2 years ago
Hi @mdv27, thanks for the report.
Please provide a repo which fails the error.
If it's easier you can upload an archive with the project and node_modules right here in your comment.
@satanTime Created repo from scratch and it does fail with same error. Let me know if more details are required.
Thanks! checking it!
So, the problem comes from @progress/kendo-angular-inputs
and only in jest. I'm working on a fix for it.
That's so quick! š® š May I know how did you find the root cause? Looking forward for the fix soon š
Basically I removed everything from your component, the test was failing, then I started to remove module by module and found out this dependency.
The final test is:
import {MockBuilder, MockRender} from 'ng-mocks';
import {TestBed} from "@angular/core/testing";
import {NgModule} from '@angular/core';
import {InputsModule} from '@progress/kendo-angular-inputs';
import {Component} from '@angular/core';
@Component({
selector: 'app-header',
template: '',
})
class HeaderComponent {}
@NgModule({
declarations: [HeaderComponent],
imports: [
InputsModule,
],
})
class AppModule {}
describe('HeaderComponent', () => {
describe('ng-mocks', () => {
beforeEach(() => MockBuilder(HeaderComponent, AppModule));
it('should create component', () => {
const fixture = MockRender(HeaderComponent, {});
const component = fixture.point.componentInstance;
expect(component).toBeDefined();
});
});
describe('TestBed', () => {
beforeEach(() => {
return TestBed.configureTestingModule({
imports: [AppModule],
}).compileComponents();
});
it('should create component', () => {
const fixture = TestBed.createComponent(HeaderComponent);
fixture.detectChanges();
const component = fixture.componentInstance;
expect(component).toBeDefined();
});
});
});
Ideally if module/dependency is mocked/stubbed, test should not trigger/run the dependency code, I assume this is not honored with @progress/kendo-angular-inputs
dep usage?
I think there is a problem how the mock of a dependency has been defined, so when Angular is creating a TestBed env, it stumbles over it.
So. Some of declarations of @progress
have empty class / function names, because of that ng-mocks treated them as arrow-function
, whereas -
is a wrong symbol for a class / function name.
jest is creating a file with a mock class called MockOfarrow-function
, and this dash has caused the failure.
Now ng-mocks
uses arrowFunction
and MockOfarrowFunction
is compatible with a class / function name and doesn't cause the issue.
v14.1.3 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.
This change is working for me. Thank you @satanTime š
Description of the bug
Unit tests are failing with below error when Angular version is updated to 14.x.x from 12.x.x.
Dependency list:
Line of code where getting below error:
Error stack:
An example of the bug
Above error stack.
Link:
Expected vs actual behavior
Test should run without error.