小编Joh*_*nny的帖子

从服务订阅 observable 时,角度单元测试管道不是一个函数

我正在编写一个单元测试来从服务订阅可观察的内容。我收到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)

unit-testing observable rxjs jestjs angular

5
推荐指数
1
解决办法
4580
查看次数

如何在 Javascript 的 foreach 循环中合并多个数组

如何在 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)

javascript arrays ecmascript-6

2
推荐指数
2
解决办法
4969
查看次数

Nestjs:无法在同一控制器中实现多个 GET 方法

我这里有一些奇怪的问题。我有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)

node.js swagger nestjs

1
推荐指数
1
解决办法
2310
查看次数