0

Creating the unit test cases for angular app, application functionality divided into module based on the requirement.

Needed components, modules and angular material components are imported in module file so that no need of import in the component files, but while executing the

ng test

returning the error for module not found since not included in component.spec.ts file.

For fixing this importing the all the modules and services inside the spec files ,is there any best and simple way to import the modules to all the spec file to avoid duplication and time consumption.

1 Answer 1

1

You could make this at least less redundant by creating a central file exporting all you slec references you regularly need.

import { FooModule } from 'foo.module.ts';
import { BarModule } from 'bar.module.ts';

export const specImports = [
  FooModule,
  BarModule
  //...
];
export const specProviders = [ /*...*/ ];

And then simply import those into your specs, allowing you to change one place when you create new providers, components and modules instead of all spec files.

Nevertheless let me add that keeping you references clean in spec files on the one hand makes sure that you don't see unrelated errors and on the other hand does not slow down your tests unnecessarily by building instances that aren't even used. But centralizing a bunch of base references surely reduces the maintenance effort!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.