I am using a selector that is retriving an array of cars, but when I tried to test I am getting:
TypeError: agency.getCars is not a function
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']);
});
How is the correct way to mock this function.
I need to use the spy object, is not necessary the entire state, we need only the type of the selector 'Agency' and the result of the function, projector is handling the stub.
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']);
});
});