我正在编写一个单元测试来从服务订阅可观察的内容。我收到pipe is not a function错误。我创建了一个玩笑间谍fundsListByClientId$并简单地返回了模拟数据。请帮助我知道我错过了什么?我使用 Jest 进行单元测试
错误:
TypeError: this._fundsService.fundsListByClientId$.pipe is not a function
Run Code Online (Sandbox Code Playgroud)
基金规格
let service: FundsService;
beforeEach(async () => {
await TestBed.configureTestingModule({
providers: [
{
provide: FundsService,
useValue: {
fundsListByClientId$: jest.fn(),
},
},
],
}).compileComponents();
});
beforeEach(() => {
service = TestBed.inject(FundsService);
});
it("Should sort fundlist object", () => {
const mockResponse = {cart: false, name: "test" };
const spyCopmponent = jest.spyOn(component, "onFundsByClientId");
jest
.spyOn(service, "fundsListByClientId$", "get")
.mockReturnValue(of(mockResponse));
component.onFundsByClientId();
service.fundsListByClientId$.subscribe((result) => {
expect(result).toEqual(mockResponse);
}); …Run Code Online (Sandbox Code Playgroud) 如何在 foreach 循环中合并多个数组。我正在尝试将所有 3imageData个数组合并到一个数组中。请告诉我是否错过了以下方法中的任何内容。
const imageArray = [
{
imageData: [
'https://via.placeholder.com/50',
'https://via.placeholder.com/60'
],
},
{
imageData: [
'https://via.placeholder.com/100'
],
},
{
imageData: [
'https://via.placeholder.com/150'
],
}
];
processImage() {
imageArray.forEach((element) => {
const imageCollection = [...element.imageData];
console.log(imageCollection);
// Expected result
//['https://via.placeholder.com/50', 'https://via.placeholder.com/60', 'https://via.placeholder.com/100', https://via.placeholder.com/150]
});
}
Run Code Online (Sandbox Code Playgroud) 我这里有一些奇怪的问题。我有2种获取方法,一种是通过companyId获取员工列表,一种是通过staffId获取员工详细信息。第二种方法getStaffById不行。如果我注释掉第一个 get 方法getStaffByCompanyId,第二个方法将按预期工作。看起来第一个 get 方法阻止了第二个方法。我在这里错过了什么吗?
@Controller('staff')
@ApiTags('Staff')
export class StaffController {
constructor(private staffService: StaffService) {}
@Get(':companyId')
@ApiResponse({
status: HttpStatus.OK,
description: 'Return staffs by id',
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'Unauthorized',
type: Error,
})
@ApiResponse({
status: HttpStatus.UNPROCESSABLE_ENTITY,
description: 'Get particular staff details',
type: Error,
})
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: 'Internal server error',
type: Error,
})
@ApiResponse({
status: HttpStatus.BAD_GATEWAY,
description: 'Internal communication error',
type: Error,
})
@ApiOperation({
operationId: 'getStaffByCompanyId',
summary: 'Get staff list that attach to the company', …Run Code Online (Sandbox Code Playgroud) angular ×1
arrays ×1
ecmascript-6 ×1
javascript ×1
jestjs ×1
nestjs ×1
node.js ×1
observable ×1
rxjs ×1
swagger ×1
unit-testing ×1