My project was created using nx schematics, and I'm having some components inside libraries that I want to unit test using jest.js. Every test fails with following errors:
● MyComponent › should create
Failed: "Zone is needed for the async() test helper but could not be found. Please make sure that your environment includes zone.js/dist/zone.js"
7 | let fixture: ComponentFixture<MyComponent>;
8 |
> 9 | beforeEach(async(() => {
| ^
10 | TestBed.configureTestingModule({
11 | declarations: [ MyComponent ]
12 | })
at Env.beforeEach (node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:41:24)
at Suite.<anonymous> (libs/componentlib/src/lib/components/my-component/my-component.component.spec.ts:9:3)
at Object.<anonymous> (libs/componentlib/src/lib/components/my-component/my-component.component.spec.ts:5:1)
● MyComponent › should create
TypeError: Cannot read property 'getComponentFromError' of null
at TestBedViewEngine._initIfNeeded (../../packages/core/testing/src/test_bed.ts:393:46)
at TestBedViewEngine.createComponent (../../packages/core/testing/src/test_bed.ts:594:10)
at Function.TestBedViewEngine.createComponent (../../packages/core/testing/src/test_bed.ts:247:36)
at Object.<anonymous> (libs/componentlib/src/lib/components/my-component/my-component.component.spec.ts:17:23)
● MyComponent › should create
expect(received).toBeTruthy()
Received: undefined
21 |
22 | it('should create', () => {
> 23 | expect(component).toBeTruthy();
| ^
24 | });
25 | });
26 |
at Object.<anonymous> (libs/componentlib/src/lib/components/my-component/my-component.component.spec.ts:23:23)
I've tried already to import zone.js in spec files, importing modules, removing async, reseting the test environment before each test, but everything fails with some different error. I should mention also that I'm using clarity components from vmware.
Here's the .spec file:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MyComponent } from './my-component.component';
describe('MyComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyComponent);
component = fixture.componentInstance;
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
I was expecting that this should work like intended when using nx. What am I missing here?