我正在使用一个选择器,它正在重新生成一个汽车数组,但当我试图测试时,我得到了。
类型错误: 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']);
});
如何正确模拟这个函数。
我需要使用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']);
});
});