반응형
    
    
    
  카르마 테스트:오류 유형:읽기 전용 속성에 할당하려고 시도했습니다.
컨트롤러를 유닛 테스트하려고 하면 오류가 발생합니다.테스트 케이스의 예상치를 디버그하면 예상치를 얻을 수 있지만 아래 오류로 인해 실패합니다.컨트롤러 변수를 잘못된 방식으로 테스트하는 것은 아닌지 또는 여기에 누락된 것은 무엇입니까?
내 사양 파일은 아래와 같습니다.
'use strict';
describe('Information.controller', function () {
beforeEach(angular.mock.module('asp'));
var InformationController, scope;
beforeEach(inject(function($controller, $rootScope) {
    scope = $rootScope.$new();
    InformationController = $controller('InformationController', {
        $scope: scope
    });
}));
fit('Should remove the object without info from the  object', function () {
    InformationController.Data = [
        {
            "ban": "03745645455",
            "accountNo": "0000drgyt456456565",
            "id": "2c4cc5e8-f360367"
        },
        {
            "ban": "27346fgh9080",
            "accountNo": "000456456ytr655680",
            "id": "2c4cc8ae-50bbf360367"
        }
    ];
    InformationController.banList = InformationController.Data.map((value, index) => (value && value.ban ? {'id': index, 'text': value.ban} : null))
    .filter(value => value);
    expect(InformationController.banList.length).toBe(3);
});
});
read only 오류는 scope.page(내 정보 컨트롤러)가 정의되지 않은 상태에서 코드가 정의되지 않은 상태에 속성을 할당하려고 시도하는 중에 발생합니다.따라서 아래와 같이 각 블록 이전에 수정됨
beforeEach(inject(function ($controller, $rootScope) {
        scope = $rootScope.$new();
        scope.page3 = {};
        InformationController = $controller('InformationController', {
            $scope: scope
        });
    }));
 
이로써 문제가 해결되었습니다.
언급URL : https://stackoverflow.com/questions/37696412/karma-testing-typeerror-attempted-to-assign-to-readonly-property
반응형
    
    
    
  'programing' 카테고리의 다른 글
| GCC는 정적 분기 예측을 위한 차선의 코드를 생성합니까? (0) | 2023.10.01 | 
|---|---|
| MySQL LOAD DATA INFILE은 이후에 메모리를 지우지 않습니다. (0) | 2023.10.01 | 
| 워드프레스에 http 헤더 추가 (0) | 2023.09.26 | 
| D3.js와 동등한 파이썬 (0) | 2023.09.26 | 
| 사용자가 마우스를 이동하지 않고 브라우저 커서를 "대기"에서 "자동"으로 이동 (0) | 2023.09.26 |