如何从一个选择器的函数中获取值?

问题描述 投票:0回答:1

我正在使用一个选择器,它正在重新生成一个汽车数组,但当我试图测试时,我得到了。

类型错误: agency.getCars不是一个函数。

describe('selectCars', () => {
    it('should return car array', () => {
    const stub = jasmine.createSpyObj<AgencyShop>({
      findAgency: {
         brand: 'BRAND_ID',
         name: 'NAME'
         getCars: () => ['Rio', 'Soul', 'Sportage']
      } as Agency
  });
  const result = selectCars.projector(stub, {
      brand: 'BRAND_ID'
  });

   expect(result).toEqual(['Rio', 'Soul', 'Sportage']);
  });

如何正确模拟这个函数。

javascript unit-testing jasmine ngrx ngrx-entity
1个回答
0
投票

我需要使用spy对象,并不需要整个状态,我们只需要选择器的类型'Agency'和函数的结果,投影仪处理的是存根。

describe('selectCars', () => {
  it('should return car array', () => {
     const stub = jasmine.createSpyObj<Agency>({
       getCars: ['Rio', 'Soul', 'Sportage'] as string[]
    });

    const result = selectCars.projector(stub, {
       brand: 'BRAND_ID'
    });

     expect(result).toEqual(['Rio', 'Soul', 'Sportage']);
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.