0

我正在使用一个选择器来检索一系列汽车,但是当我尝试测试时,我得到:

TypeError: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']);
  });

模拟此功能的正确方法是什么。

4

1 回答 1

0

我需要使用间谍对象,不需要整个状态,我们只需要选择器“代理”的类型和函数的结果,投影仪正在处理存根。

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']);
  });
});
于 2020-04-28T05:41:15.333 回答