unitarios unitarias unit test pruebas karma angularjs unit-testing karma-jasmine angularjs-controller

angularjs - unitarias - test unitarios angular 5



Karma testing: TypeError: intento de asignaciĆ³n a propiedad de solo lectura (1)

Cuando intento realizar una prueba unitaria de mi controlador, obtengo el error. Cuando depuro las pruebas del testcase, obtengo el valor esperado pero falla con el error que se muestra a continuación. ¿manera?

Mi archivo de especificaciones está abajo

''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); }); });


el error de solo lectura es causado por scope.page (en mi InformationController) que no está definido y luego el código está tratando de asignar una propiedad a undefined.

beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); scope.page3 = {}; InformationController = $controller(''InformationController'', { $scope: scope }); }));

Esto solucionó el problema.