programing

카르마 테스트:오류 유형:읽기 전용 속성에 할당하려고 시도했습니다.

sourcejob 2023. 9. 26. 22:20
반응형

카르마 테스트:오류 유형:읽기 전용 속성에 할당하려고 시도했습니다.

컨트롤러를 유닛 테스트하려고 하면 오류가 발생합니다.테스트 케이스의 예상치를 디버그하면 예상치를 얻을 수 있지만 아래 오류로 인해 실패합니다.컨트롤러 변수를 잘못된 방식으로 테스트하는 것은 아닌지 또는 여기에 누락된 것은 무엇입니까?

내 사양 파일은 아래와 같습니다.

'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

반응형