#I got error when try e2e test

80 messages · Page 1 of 1 (latest)

lapis pulsar
#

Anyway i use old version of nestjs core

"@nestjs/core": "^7.6.15"

How to fix it? Thanks.

winter mulch
#

use relative paths

#

otherwise you'll need to play with your jest config a bit

solid salmon
#

Relative paths, or update jest's moduleNameMapper option to support the absolute paths.

winter mulch
#

I feel that this should be in our FAQ page :/
it's so common and isn't related with nestjs itself but since the CLI generates jest files, I guess it would make sense

lapis pulsar
#

this my tsconfig

#

this my jest config

solid salmon
#

Shouldn't it be something like "^src/(.*)$": "<rootDir>/src/$1"? It's regex, so you have to have a capture group () to use the group reference $1

lapis pulsar
#

let me try

solid salmon
#

Failed how? Same way or something new?

lapis pulsar
solid salmon
#

And Backend\test\src\models would be the correct path? Or should you be doing <rootDir>/../src/$1?

lapis pulsar
#

oh wrong, should be <rootDir>/../src/$1

winter mulch
#

yeah, it depends on which directory your jest-e2e.json is located at since it will be the <rootDir>

solid salmon
#

Progress! What's under your src/connection/Connection.ts class?

lapis pulsar
#

Connection from typeorm anyway

solid salmon
#

Why?

lapis pulsar
#

and i use typeorm for reset data for while

#

should i remove?

solid salmon
#

Okay? But you don't need to add Connection to the imports array

lapis pulsar
#

ohh wait

solid salmon
lapis pulsar
#

any way this my test

#

correct or not ?

solid salmon
#

It looks fine

#

app is showing up as undefined because Nest can't create the application

#

Why? Dunno, would need logs where the error is reported 🙂

lapis pulsar
solid salmon
lapis pulsar
#

this my first time i use test

solid salmon
#

Okay?

lapis pulsar
#

its okay right?

solid salmon
#

Why would it not be?

#

You didn't change anything from when the project was created, right?

#

At least in terms of the test command

lapis pulsar
solid salmon
#

I already told you, to know why your test is failing, you need to look at the logs during the test. Most likely Nest is reporting something failing in the DI and you're blatantly ignoring it and fishing for help

solid salmon
#

It should be in the terminal

lapis pulsar
solid salmon
#

Right there. "Nest cannot resolve dependency Connection". Where do you have TypeormModule.forRoot()?

solid salmon
#

Well, that's where Connection comes from. How would you expect to inject something that doesn't exist?

winter mulch
#

that's why

solid salmon
#

Either add only AppModule to the imports array of your test and import everything or add just TypeOrmModule.forRoot()

lapis pulsar
#

i dont understand why i got http status 400, i check my swagger and found my data

winter mulch
#

how the controller looks like?

lapis pulsar
winter mulch
#

looks fine to me 🤔

lapis pulsar
solid salmon
#

That usually means the server didn't start up for some reason

lapis pulsar
#

i mean local

#

200 status code

solid salmon
#

You run await app.init(( that should be enough for supertest

lapis pulsar
solid salmon
#

Your tsconfig is probably fine

lapis pulsar
solid salmon
#

Do you have a @Get() route in the controller?

solid salmon
lapis pulsar
#

wait

lapis pulsar
solid salmon
lapis pulsar
#

SOLVED