我正在尝试在 Nest.js 应用程序中使用 supertest + jest 端到端测试我的 graphql 服务,但不断收到此错误:
错误:无法 POST /graphql (404)
我尝试了很多方法,但由于该错误而无法使测试完全运行。
下面是我的测试文件:
import request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { GatewayAppModule } from '../../../app-gateway.module';
import { AppModule } from '../../../app.module';
import { CreateAccountArgs } from '../dto/create-account.args';
jest.mock('graphql-moment', () => ({
GraphQLDate: jest.fn(),
}));
describe('Auth resolver: Authentication module e2e test', () => {
let mainApp: INestApplication;
let gatewayApp: INestApplication;
beforeAll(async () => {
const mainAppModuleRef: TestingModule = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 Nest JS 应用程序中进行第三方 API 调用。由于 Nest JS 在底层使用 Axios,并且在其文档中拥有专门的页面https://docs.nestjs.com/techniques/http-module,因此我确保遵循文档中提供的实现,但我保留当我尝试通过 Nestjs 的 httpModule 发出 HTTP 请求时,遇到httpService undefined错误。我不确定我错过了什么,我尝试在这里搜索相关问题,但没有成功。请帮忙看一下,下面是我的代码示例。
银行验证.service.ts
import { HttpService } from '@nestjs/common';
import { Observable } from 'rxjs';
import { config } from 'dotenv';
import { AxiosResponse } from 'axios';
config();
export class BankVerificationService {
constructor(private httpService: HttpService){}
getBanks(countryCode): Observable<AxiosResponse<any>> {
console.log(this.httpService, '===============')
return this.httpService.get(`https://api.flutterwave.com/v3/banks/${countryCode}`, {
headers: {
Authorization: `Bearer ${process.env.FLUTTERWAVE_TEST_SECRET}`
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
下面是我的 Axios HTTP 模块配置
import { Module, HttpModule } …Run Code Online (Sandbox Code Playgroud)