e2e testing not working with fastify V3
See original GitHub issueBug Report
Original issue here https://github.com/fastify/help/issues/228. While the workaround in that thread works, it leaves open handles and has to hardcode port number. Also, they seem to conclude that something in app.init
has to be changed.
Current behavior
TypeError: Cannot read property 'length' of undefined
at next (../node_modules/fastify/lib/route.js:374:32)
at preParsingHookRunner (../node_modules/fastify/lib/route.js:405:3)
at runPreParsing (../node_modules/fastify/lib/route.js:356:5)
at Object.routeHandler [as handler] (../node_modules/fastify/lib/route.js:334:7)
at Router.lookup (../node_modules/find-my-way/index.js:356:14)
Input Code
main.ts
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
await app.listen(3000);
}
bootstrap();
app.e2e-spec.ts
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
import { FastifyAdapter } from '@nestjs/platform-fastify';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication(new FastifyAdapter());
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
Expected behavior
Test pass. (It works as expected if using fastify V2 and @nestjs/platform-fastify@7.2)
Possible Solution
Environment
Nest version: X.Y.Z
For Tooling issues:
- Node version: 7.4.2
- Platform: Ubuntu
Others:
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
NestJS + Fastify e2e testing: Jest did not exit one second after ...
While running end-to-end tests of NestJS+Fastify application I noticed the following warnings: Jest did not exit one second after the test ...
Read more >Testing - Fastify
Testing is one of the most important parts of developing an application. Fastify is very flexible when it comes to testing and is...
Read more >Testing a Fastify CRUD application using mongodb
Learn how to implement tests on a nodejs application within fastify and tap. Read from the local db and assert all your conditions....
Read more >Test your Fastify REST API With Node Tap - YouTube
In this video, we test a Fastify REST API with Node Tap. You will learn how to mock imports and test against a...
Read more >Testing | NestJS - A progressive Node.js framework
Nest: automatically scaffolds default unit tests for components and e2e tests for applications; provides default tooling (such as a test runner that builds...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Use
FastifyNestApplication
instead ofINestApplication
. You can cast this type as necessary. You can see an example here@Summon528 Please share an example here. I have similar problem, using fastify.inject is not recognized on INestApplication
Property 'inject' does not exist on type 'INestApplication'.