茉莉角测试比较对象打字稿?

时间:2019-12-19 10:15:30

标签: angular typescript jasmine

我正在尝试比较茉莉中的两个对象,但它们并不相同 这是我的例子

服务

import { Injectable } from '@angular/core';
import { ExpertOperational, ExpertWorkingHours, WeekDays, ExpertWorkingDay } from './experts';

@Injectable()
export class ExpertOperationsService {
    expertOperational: ExpertOperational = new ExpertOperational;
    constructor() { }

    getExpertOperationalModel(): ExpertOperational {
        const expertWorkingDay: ExpertWorkingDay[] = [];
        const expertWorkingHours = Object.values(WeekDays);
        expertWorkingHours.forEach(day => {
            expertWorkingDay.push(
                new ExpertWorkingDay(
                    WeekDays[day as unknown as keyof WeekDays],
                    new ExpertWorkingHours(
                        false,
                        '',
                        ''
                    ),
                    new ExpertWorkingHours(
                        false,
                        '',
                        ''
                    )
                )
            );
        });
        this.expertOperational = {
            'comment': '',
            'outOfService': '',
            'score': '',
            'supplierNumber': '',
            'useSlots': false,
            'workingDay': expertWorkingDay,
            'workSpeedSurvey': '',
            'workSpeedVisit': ''
        };
        return this.expertOperational;
    }
}

假对象

export const fakeExpertOperational: ExpertOperational = {
    comment: '',
    outOfService: '',
    score: '',
    supplierNumber: '',
    useSlots: false,
    workingDay:   [
        {
            weekDay: 'MONDAY',
            operationalAM: {
                fixed: false,
                startTime: '',
                endTime: ''
            },
            operationalPM: {
                fixed: false,
                startTime: '',
                endTime: ''
            }
        },
        {
            weekDay: 'TUESDAY',
            operationalAM: {
                fixed: false,
                startTime: '',
                endTime: ''
            },
            operationalPM: {
                fixed: false,
                startTime: '',
                endTime: ''
            }
        },
        {
            weekDay: 'WEDNESDAY',
            operationalAM: {
                fixed: false,
                startTime: '',
                endTime: ''
            },
            operationalPM: {
                fixed: false,
                startTime: '',
                endTime: ''
            }
        },
        {
            weekDay: 'THURSDAY',
            operationalAM: {
                fixed: false,
                startTime: '',
                endTime: ''
            },
            operationalPM: {
                fixed: false,
                startTime: '',
                endTime: ''
            }
        },
        {
            weekDay: 'FRIDAY',
            operationalAM: {
                fixed: false,
                startTime: '',
                endTime: ''
            },
            operationalPM: {
                fixed: false,
                startTime: '',
                endTime: ''
            }
        },
        {
            weekDay: 'SATURDAY',
            operationalAM: {
                fixed: false,
                startTime: '',
                endTime: ''
            },
            operationalPM: {
                fixed: false,
                startTime: '',
                endTime: ''
            }
        },
        {
            weekDay: 'SUNDAY',
            operationalAM: {
                fixed: false,
                startTime: '',
                endTime: ''
            },
            operationalPM: {
                fixed: false,
                startTime: '',
                endTime: ''
            }
        }
    ],
    workSpeedSurvey: '0',
    workSpeedVisit: '0'
};

和我的 service.spec.ts

  it('should create working model', () => {
            // GIVEN
            const expertOperational = fakeExpertOperational;
            // WHEN
            const expectedexpertOperational = service.getExpertOperationalModel();
            // THEN
            expect(Object.assign({}, expectedexpertOperational)).toEqual(Object.assign({}, expertOperational));
        });

但是我遇到了类似的错误 预期$ .workingDay [0]是一种对象,但它是ExpertWorkingDay({weekDay:'MONDAY',operatingAM:ExpertWorkingHours({固定:false,startTime:'',endTime:``})),operatingPM :ExpertWorkingHours({固定:false,开始时间:”,结束时间:”}}})。

0 个答案:

没有答案