Ich probiere den Komponententest in m-Generator. Ich habe $ scope in die Testspezifikationsdatei injiziert, sehe aber, wie dieser Fehler behoben werden kann. Ich injiziere einige Dateien, nachdem kam die gleiche unterschiedliche injizieren Sie den Fehler.TypeError: undefined ist kein Objekt (Bewertung 'screen.orientation.lock')
Controller-Datei:
'use strict';
(function() {
angular.module('main').controller('HomeCtrl', HomeCtrl);
HomeCtrl.$inject = ['$log', 'SignOut', '$state', '$cordovaNetwork',
'$auth', 'CommonService', '$scope', '$ionicPopup', 'Analytics',
'BackupServices', '$translate', '$ionicPlatform'];
function HomeCtrl ($log, SignOut, $state, $cordovaNetwork, $auth,
CommonService, $scope, $ionicPopup, Analytics, BackupServices,
$translate, $ionicPlatform) {
$log.log('HomeCtrl got called');
var vm = this;
vm.password = {
input: '', // by user
strength: ''
};
vm.grade = function() {
var size = vm.password.input.length;
if (size > 8) {
vm.password.strength = 'strong';
} else if (size > 3) {
vm.password.strength = 'medium';
} else {
vm.password.strength = 'weak';
}
};
vm.grade();
function activate() {
screen.orientation.lock('portrait');
Analytics.trackPage('Home-Page');
} })();
Dies ist Datei js Karma Test ich homectrl injiziert aber homectrl einige Plugins haben während des Testcode auszuführen hat
Test Spec-Datei:
describe('module: main, controller: HomeCtrl', function() {
beforeEach(module('main'));
beforeEach(module('ngHtml2Js'));
// instantiate controller
var HomeCtrl;
beforeEach(inject(function ($controller, $rootScope) {
var scope = $rootScope.$new();
HomeCtrl = $controller('HomeCtrl',{ $scope: scope });
}));
describe('.grade()', function() {
it('should classify asd as weak', function() {
HomeCtrl.password.input = 'asd';
HomeCtrl.grade();
expect(HomeCtrl.password.strength).toEqual('weak');
});
it('should classify asdf as medium', function() {
HomeCtrl.password.input = 'asdf';
HomeCtrl.grade();
expect(HomeCtrl.password.strength).toEqual('medium');
});
it('should classify asdfasdfasdf as strong', function() {
HomeCtrl.password.input = 'asdfasdfasdf';
HomeCtrl.grade();
expect(HomeCtrl.password.strength).toEqual('strong');
});
}); });