2016-06-16 20 views
6

Ogni volta che provo a iniettare un servizio angolare, il mio semplice test Jasmine fallisce. Tuttavia, se rimuovo l'iniezione, funziona. Il seguente causa un errore di essere gettato:angolare primaIniezione che causa un semplice test fallito

describe('rule.js file', function() { 
 
    beforeEach(module('myModule')); 
 
    beforeEach(inject(function($controller) { 
 
    console.log('What the heck is wrong???: ' + $controller); 
 
    })); 
 
    it('foo should be equal to 1', function() { 
 
    expect(1).toBe(1); 
 
    }); 
 
});
Questo è l'errore:

PhantomJS 2.1.1 (Windows 7 0.0.0) rule.js file foo should be equal to 1 FAILED

Tuttavia, se io commento la linea iniettare in questo modo:

describe('rule.js file', function() { 
 
    beforeEach(module('myModule')); 
 
    it('foo should be equal to 1', function() { 
 
    expect(1).toBe(1); 
 
    }); 
 
});

Il test è valido.

Qualcuno ha qualche indizio su cosa potrebbe essere sbagliato?

Edit: Ecco mia karma.conf inclusi file

'bower_components/angular/angular.js', 
    'bower_components/angular-animate/angular-animate.js', 
    'bower_components/angular-aria/angular-aria.js', 
    'bower_components/angular-cookies/angular-cookies.js', 
    'bower_components/angular-messages/angular-messages.js', 
    'bower_components/angular-resource/angular-resource.js', 
    'bower_components/angular-route/angular-route.js', 
    'bower_components/angular-sanitize/angular-sanitize.js', 
    'bower_components/angular-touch/angular-touch.js', 
    'bower_components/angular-ui-router/release/angular-ui-router.js', 
    'bower_components/angular-strap/dist/angular-strap.js', 
    'bower_components/angular-strap/dist/angular-strap.tpl.js', 
    'bower_components/angular-deferred-bootstrap/angular-deferred-bootstrap.js', 
    'bower_components/angular-ui-router.stateHelper/statehelper.js', 
    'bower_components/lz-string/libs/lz-string.min.js', 
    'bower_components/angular-ui-scroll/dist/ui-scroll.js', 
    'bower_components/angular-ui-scrollpoint/dist/scrollpoint.js', 
    'bower_components/angular-ui-event/dist/event.js', 
    'bower_components/angular-ui-mask/dist/mask.js', 
    'bower_components/angular-ui-validate/dist/validate.js', 
    'bower_components/angular-ui-indeterminate/dist/indeterminate.js', 
    'bower_components/angular-ui-uploader/dist/uploader.js', 
    'bower_components/angular-ui-utils/index.js', 
    'bower_components/angular-recaptcha/release/angular-recaptcha.js', 
    'bower_components/angular-local-storage/dist/angular-local-storage.js', 
    'bower_components/angular-bowser/src/angular-bowser.js', 
    'bower_components/ngAnimate-animate.css/animate.js', 
    'bower_components/angular-truncate/src/truncate.js', 
    'bower_components/blob-polyfill/Blob.js', 
    'bower_components/file-saver.js/FileSaver.js', 
    'bower_components/angular-file-saver/dist/angular-file-saver.bundle.js', 
    'bower_components/ng-idle/angular-idle.js', 
    'bower_components/jasmine/lib/jasmine-core/jasmine.js', 
    'bower_components/angular-mocks/angular-mocks.js', 
    "app/scripts/viewlevels.js", 
    "app/scripts/global.js", 
    "app/scripts/hrbui.js", 
    "app/scripts/hrb-mask.js", 
    'app/scripts/**/*.js', 
    'unit-tests/global.js', 
    'unit-tests/specs/**/*.js', 
+0

puoi incollare i file inclusi karma.conf – Don

+0

@Don Ho aggiunto i miei file karma.conf nel mio post originale. –

+1

puoi verificare se le angolature angolari sono della stessa versione – Don

risposta

0

Il motivo per cui passa è perché davvero non sta testando nulla. C'è ancora un po 'di più che devi fare con il controller prima che il test possa effettivamente essere eseguito. Penso che se si struttura le cose come qui di seguito, dovrebbe funzionare:

describe('rule.js file', function() { 
 
    var controller; 
 
    beforeEach(module('myModule')); 
 
    beforeEach(inject(function(_$controller_) { 
 
    controller = _$controller_('yourControllerName', {$scope: $scope}); 
 
    
 
    console.log('What the heck is wrong???: ' + controller); 
 
    })); 
 
    it('foo should be equal to 1', function() { 
 
    expect(1).toBe(1); 
 
    }); 
 
});

io sono un po 'tardi per la risposta a quanto pare, ma spero che questo possa aiutare qualcuno.

Problemi correlati