typescript jasmin mock / spy public property

时间:2018-03-11 03:21:36

标签: angular typescript angularjs-components

export class Thing {
    public thingForm: any;
    public loading: boolean = true;
    constructor{...}
    public $onInit(): void {...}
    public submit = (): void => {
        ...
        this.doValidation();
    }
    private doValidation = (): void => {
        this.loading = false;
        this.thingForm.name.$setValidity('name', false);
    }
}

it('should fail validation', () => {
    ctrl = getController();
    ctrl.submit();
    $scope.apply();
    expect(ctrl.loading).toBeFalsy();
});

好的,所以我正在尝试为这个场景编写一个测试但是失败了。尝试做jasmin.createSpy / createSpyObject,窥探属性等等,但似乎没有任何效果。我一直收到错误显示:

undefined is not an object (evaluating _this.thingForm.name)...

有人可以告诉我如何嘲笑这件事?提前谢谢。

0 个答案:

没有答案