angular test error TypeError:尝试分配给readonly属性

时间:2017-10-19 19:26:00

标签: angular phantomjs karma-jasmine angular-test

当我尝试为fixture.debugElement.nativeElement的属性赋值时,它会给我错误。

fixture.debugElement.nativeElement.clientWidth = 4501;

我检入了调试器,fixture.debugElement.nativeElement.clientWidth存在,而不是undefinednull

chrome-luncher中的

错误

TypeError: Cannot assign to read only property 'clientWidth' of object '[object HTMLDivElement]'
        at Object.<anonymous> Users/k26686/aniruddh/develop/experiment/udc-spet-experiment/pre-commit-keywords/shepherd/src/app/shared/components/ellipsis-overflow/ellipsis-overflow.component.spec.ts:67:51)
...
Users/k26686/aniruddh/develop/experiment/udc-spet-experiment/pre-commit-keywords/shepherd/node_modules/zone.js/dist/zone.js:141:1)
        at Object.<anonymous> Users/k26686/aniruddh/develop/experiment/udc-spet-experiment/pre-commit-keywords/shepherd/node_modules/zone.js/dist/jasmine-patch.js:104:1)

phantomjs-luncher

出错
TypeError: Attempted to assign to readonly property. in http://localhost:9876/_karma_webpack_/main.bundle.js (line 14691)
    http://localhost:9876/_karma_webpack_/main.bundle.js:14691:43
    invoke@http://localhost:9876/_karma_webpack_/polyfills.bundle.js:12951:31
    onInvoke@http://localhost:9876/_karma_webpack_/vendor.bundle.js:136846:45

0 个答案:

没有答案