question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to setup Karma/Jasmine with Typescript support for a NestJs project

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[ ] Feature request
[ x ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

The testing documentation is great but there’s no setup part and and the starters probably don’t want to enforce any testing framework, we have to do that setup ourselves, which is pretty hard for angular-cli user 😅 (focus on writing code, not setting things up)

A bit of help would be veeeeery welcome for that and I’m guessing that I’m not the only one who want that kind of setup so maybe there should be some section in doc how to make a basic setup for testing a Nest project (at least with Typescript support).

So I’m creating a starter NestJs for the back, Angular for the front: https://github.com/maxime1992/nest-angular-starter

I used karma-typescript and made a setup. It ended up with some errors related to my karma conf, which has now been solved.

The only last error is directly related to Nest and/or Express I think. When I launch the tests I end up with:

{ "message": "An error was thrown in afterAll\nUncaught TypeError: Object prototype may only be an Object or null: undefined", "str": "An error was thrown in afterAll\nUncaught TypeError: Object prototype may only be an Object or null: undefined" }

And I can also have this more complete stacktrace:

Chromium 64.0.3282 (Ubuntu 0.0.0) ERROR { "message": "Uncaught TypeError: Object prototype may only be an Object or null: undefined\nat /tmp/karma-typescript-bundle-26778Zp2MqPkTFGxe.js:57170:18\n\nTypeError: Object prototype may only be an Object or null: undefined\n at Function.create (<anonymous>)\n at Object.global.wrappers./home/maxime/Documents/nest-angular-starter/node_modules/express/lib/request.js.depd (/tmp/karma-typescript-bundle-26778Zp2MqPkTFGxe.js:57170:18)\n at require (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:17:25)\n at /home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:18:24\n at Object.global.wrappers./home/maxime/Documents/nest-angular-starter/node_modules/express/lib/express.js.body-parser (/tmp/karma-typescript-bundle-26778Zp2MqPkTFGxe.js:57683:11)\n at require (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:17:25)\n at /home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:18:24\n at Object.global.wrappers./home/maxime/Documents/nest-angular-starter/node_modules/express/index.js../lib/express (/tmp/karma-typescript-bundle-26778Zp2MqPkTFGxe.js:57787:18)\n at require (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:17:25)\n at /home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:18:24", "str": "Uncaught TypeError: Object prototype may only be an Object or null: undefined\nat /tmp/karma-typescript-bundle-26778Zp2MqPkTFGxe.js:57170:18\n\nTypeError: Object prototype may only be an Object or null: undefined\n at Function.create (<anonymous>)\n at Object.global.wrappers./home/maxime/Documents/nest-angular-starter/node_modules/express/lib/request.js.depd (/tmp/karma-typescript-bundle-26778Zp2MqPkTFGxe.js:57170:18)\n at require (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:17:25)\n at /home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:18:24\n at Object.global.wrappers./home/maxime/Documents/nest-angular-starter/node_modules/express/lib/express.js.body-parser (/tmp/karma-typescript-bundle-26778Zp2MqPkTFGxe.js:57683:11)\n at require (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:17:25)\n at /home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:18:24\n at Object.global.wrappers./home/maxime/Documents/nest-angular-starter/node_modules/express/index.js../lib/express (/tmp/karma-typescript-bundle-26778Zp2MqPkTFGxe.js:57787:18)\n at require (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:17:25)\n at /home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/client/commonjs.js:18:24" }

Expected behavior

I’d just love to be able to kickstart a Nest app and focus on code/tests. If anybody could help me make that works, then maybe we could also start a dedicated documentation section for that kind of setup?

Minimal reproduction of the problem with instructions

You can find more information where I started this issue here: https://github.com/monounity/karma-typescript/issues/32#issuecomment-370177855

I also have a repo where you can try it on your own:

git clone https://github.com/maxime1992/nest-angular-starter.git
git checkout feat/init-repo
yarn
yarn run back:test

What is the motivation / use case for changing the behavior?

Focus on code/tests, not tooling

Environment


Nest version: 4.6.5
 
For Tooling issues:
- Node version: 8.2
- Platform:  Ubuntu

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
CoreyColecommented, Jun 1, 2018

I actually like this solution more:

  • remove exclude **/*.spec.ts from tsconfig.json
  • add this is tsconfig.json after compilerOptions
"typeAcquisition": {
    "include": [
      "jest"
    ]
  }
2reactions
psaunderscommented, Mar 8, 2018

I agree there is a missing step in the testing documentation, if you following along with the docs doing the Cats examples you will get an error saying “cannot find name ‘describe’” on the tests. It’d be really great if the demo project had a basic test in it so that the package.json file is in a good state.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to setup Karma/Jasmine with Typescript support for a ...
How to setup Karma/Jasmine with Typescript support for a NestJs project.
Read more >
First steps | NestJS - A progressive Node.js framework
Setting up a new project is quite simple with the Nest CLI. With npm installed, you can create a new Nest project with...
Read more >
Build a Simple API in TypeScript and NestJS - Bits and Pieces
First, we are going to install the NestJS CLI, so open the terminal of your choice and type: $ npm i -g @nestjs/cli....
Read more >
TypeScript starter project w/ Webpack 4, Karma, Jasmine
This tutorial showcases a starter project for people who want to use TypeScript w/ a stater project already setup to deploy to browsers ......
Read more >
Getting started with continuous integration for Nest.js APIs
When the installation process is complete, you can import the TypeOrmModule into the root of the application. Updating the TypeScript root ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found