嗨,我一直在尝试为我的注册服务编写测试用例。它有一个 url,它发送 4 个值。服务如下:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
interface registerResponse {
success: boolean,
message: string
}
@Injectable()
export class AuthService {
private _regurl ="http://localhost:3000/api/register"
constructor(private http: HttpClient) { }
registerUser(username,email,date, password) {
return this.http.post<registerResponse>(this._regurl, {
username,
email,
date,
password
})
}
}
我仍在学习如何编写测试用例,我试图让 registerResponse 工作。
这是我到目前为止所写的
import { TestBed, async, inject } from '@angular/core/testing';
import {
HttpModule,
Http,
Response,
ResponseOptions,
XHRBackend
} from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { AuthService } from './auth.service';
import { HttpClient } from '@angular/common/http'
describe('RegisterService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
{ provide: HttpClient, useValue: 'http://localhost:3000/api/register' },
AuthService,
{ provide: XHRBackend, useClass: MockBackend },
]
});
});
我知道这并不多,我只定义了 mockbackend,但任何帮助都会得到帮助
谢谢你