I have a simple spec written for a component, and my question is around the behavior of the test.
To test will check if a component is created. It looks as though when I run the test, the suite is first compiling and running the Component class, checking for certain variable states, and if they are not met, the test is failing.
Please see the following case for example:
Component Constructor:
constructor(
public route: ActivatedRoute,
public pageService: PageService,
private homeService: HomeService,
public staticInfoService: StaticInfoService,
private lang: LangService,
public router: Router,
public usersService: UsersService,
) {
super(pageService, route);
this.route.data.subscribe(data => {
this.entityCounts = data.number;
console.log(' +++ entity counts are ', data.number);
});
this.getRecentSelections();
this.setEntityTotals();
}
the test for this component is pretty straightforward - check if the component is defined.
Component.spec.ts
fit('should create', () => {
expect(component).toBeTruthy();
});
and i belive the spec is set up correctly. However the error message I receive when running the test is :
TypeError: data is null in src/test.ts (line 46535)
however I have mocked this route out, complete with the data.
class MockRouter {
navigate = jasmine.createSpy('navigate');
data = {
value: 100,
};
}
expect(mockRouter.data).toBeDefined();
and when expecting it to be defined, the same error message is thrown.
if someone could provide insight as to why exactly this test is causing this issue, it would be most appreciated. thanks,