This project reproduces a bug related to test. When we execute npm test
command we face the following error
FAIL my-app apps/my-app/src/app/tests/test-app.spec.ts
● Test suite failed to run
ReferenceError: data_interface_1 is not defined
17 | export class DataState {
18 | @Selector()
> 19 | static getDataIds(state: DataStateModel): IDataIds {
| ^
20 | return state.ids;
21 | }
22 |
at Object.<anonymous> (../../libs/features/src/app/shared/states/data/data.state.ts:19:45)
at Object.<anonymous> (../../libs/features/src/app/app.component.ts:4:1)
at Object.<anonymous> (../../libs/features/src/index.ts:1:1)
at Object.<anonymous> (src/app/tests/test-app.spec.ts:2:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 3.028 s
The problem has been solved by barbados-clemens PR
This project reporduces a bug related to test. When we execute npm test
command we face the following error
> nx run my-app:test
Determining test suites to run...
ngcc-jest-processor: running ngcc
FAIL my-app apps/my-app/src/app/tests/test-app.spec.ts
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'child')
8 | imports: [
9 | TestModule.forRoot(
> 10 | EnvServiceProvider.useFactory().parent.child
| ^
11 | ? {
12 | id: 'test',
13 | }
at Object.<anonymous> (../../libs/features/src/app/shared/auth/auth.module.ts:10:45)
at Object.<anonymous> (../../libs/features/src/app/core/core.module.ts:4:1)
at Object.<anonymous> (../../libs/features/src/app/app.module.ts:6:1)
at Object.<anonymous> (../../libs/features/src/index.ts:6:1)
at Object.<anonymous> (src/app/tests/test-app.spec.ts:2:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 3.926 s
Ran all test suites.
In apps/my-app/src/app/tests/test-app.spec.ts
file there is an import from the local module @features
. We import only two elements (DataState
and IDataIds
) from this module. The error comes from AuthModule
imported by CoreModule
which is imported by AppModule
. It seems that Jest is trying to resolve all exported elements from libs/features/src/index.ts
.
This project was generated using Nx.
🔎 Smart, Fast and Extensible Build System
10-minute video showing all Nx features
Nx supports many plugins which add capabilities for developing different types of applications and different tools.
These capabilities include generating applications, libraries, etc as well as the devtools to test, and build projects as well.
Below are our core plugins:
- Angular
ng add @nrwl/angular
- React
ng add @nrwl/react
- Web (no framework frontends)
ng add @nrwl/web
- Nest
ng add @nrwl/nest
- Express
ng add @nrwl/express
- Node
ng add @nrwl/node
There are also many community plugins you could add.
Run ng g @nrwl/angular:app my-app
to generate an application.
You can use any of the plugins above to generate applications as well.
When using Nx, you can create multiple applications and libraries in the same workspace.
Run ng g @nrwl/angular:lib my-lib
to generate a library.
You can also use any of the plugins above to generate libraries as well.
Libraries are shareable across libraries and applications. They can be imported from @workspace/mylib
.
Run ng serve my-app
for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
Run ng g component my-component --project=my-app
to generate a new component.
Run ng build my-app
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Run ng test my-app
to execute the unit tests via Jest.
Run nx affected:test
to execute the unit tests affected by a change.
Run ng e2e my-app
to execute the end-to-end tests via Cypress.
Run nx affected:e2e
to execute the end-to-end tests affected by a change.
Run nx graph
to see a diagram of the dependencies of your projects.
Visit the Nx Documentation to learn more.
Nx Cloud pairs with Nx in order to enable you to build and test code more rapidly, by up to 10 times. Even teams that are new to Nx can connect to Nx Cloud and start saving time instantly.
Teams using Nx gain the advantage of building full-stack applications with their preferred framework alongside Nx’s advanced code generation and project dependency graph, plus a unified experience for both frontend and backend developers.
Visit Nx Cloud to learn more.