19

जब मैं अपने नियंत्रक का परीक्षण करने की कोशिश कर रहा हूं तो मुझे त्रुटि मिल रही है। जब मैं टेस्टकेस की उम्मीद को डीबग करता हूं तो मुझे अपेक्षित मूल्य मिल रहा है लेकिन यह नीचे त्रुटि के साथ विफल रहा है। मुझे यहां याद आ रही है या क्या मैं नियंत्रक चर का गलत तरीके से परीक्षण कर रहा हूं?कर्म परीक्षण: TypeError: केवल पढ़ने योग्य संपत्ति को असाइन करने का प्रयास

मेरे कल्पना फ़ाइल नीचे

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

उत्तर

26

केवल पढ़ने के लिए त्रुटि (मेरी InformationController में) scope.page के कारण होता है अपरिभाषित किया जा रहा है और उसके बाद कोड एक संपत्ति के रूप में संशोधित beforeEach ब्लॉक undefined.Hence को आवंटित करने के लिए कोशिश कर रहा है

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

इस मुद्दे को हल किया गया।

संबंधित मुद्दे