akveo / ngx-admin-bundle-support

Support repository for ngx-admin backend bundles with issues tracking, instructions and code samples
58 stars 32 forks source link

fix(node-nest-starter-2020-04-03): backend test commands fail #65

Open mavogel opened 4 years ago

mavogel commented 4 years ago

Problem

The test commands for the backend like

npm test
npm run test:e2e

fail due to different reasons:

  1. npm test due to the DI cannot be resolved:

    
    ts-jest[versions] (WARN) Version 25.1.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
    FAIL  src/app.controller.spec.ts
    AppController
    root
      ✕ should return "API is up and running!" (14ms)
    
    ● AppController › root › should return "API is up and running!"
    
    Nest can't resolve dependencies of the AppController (AppService, ?). Please make sure that the argument at index [1] is available in the _RootTestModule context.
    
      at Injector.lookupComponentInExports (../node_modules/@nestjs/core/injector/injector.js:180:19)
    
    ● AppController › root › should return "API is up and running!"
    
    TypeError: Cannot read property 'healthCheck' of undefined
    
      23 |   describe('root', () => {
      24 |     it('should return "API is up and running!"', () => {
    > 25 |       expect(appController.healthCheck()).toBe('API is up and running!');
         |                            ^
      26 |     });
      27 |   });
      28 | });
    
      at Object.it (app.controller.spec.ts:25:28)

Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 2.155s, estimated 3s


2. `npm run test:e2e` it cannot connect to the database although in `npm start run:dev` things work fine. I run it as described in #64 
```sh
> jest --config ./test/jest-e2e.json

ts-jest[versions] (WARN) Version 25.1.0 of jest installed has not been 
tested with ts-jest. If you're experiencing issues, consider using a su
pported version (>=22.0.0 <24.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
[Nest] 94172   - 28/04/2020, 12:17   [MongooseModule] Unable to connect
 to the database. Retrying (1)...
[Nest] 94172   - 28/04/2020, 12:17   [MongooseModule] Unable to connect
 to the database. Retrying (2)... +3007ms
 FAIL  test/app.e2e-spec.ts (7.169s)
  AppController (e2e)
    ✕ / (GET) (5008ms)

  ● AppController (e2e) › / (GET)

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
wleecarter commented 4 years ago

Hi @mavogel - here's a fix for the failing unit test: https://github.com/akveo/ngx-admin-bundle-support/issues/72