我在PhantomJS ReferenceError: Can't find variable: module in www/signin/tests/signin.service.tests.js
和ReferenceError: Can't find variable: inject in www/signin/tests/signin.service.tests.js
的终端输出中收到错误,在下面的代码中调用它们。
describe('signinService', function(){
var controller,
deferredSigin,
signinServiceMock,
stateMock,
hasClass = function (element, cls) {
return element.getAttribute('class').then(function (classes) {
return classes.split(' ').indexOf(cls) !== -1;
});
};
beforeEach(function(){
module('app');
});
// disable template caching
beforeEach(module(function($provide, $urlRouterProvider) {
$provide.value('$ionicTemplateCache', function(){} );
$urlRouterProvider.deferIntercept();
}));
beforeEach(inject(function($controller, $q){
deferredSigin = $q.defer();
signinServiceMock = {
signin: jasmine.createSpy('signin spy').and.returnValue(deferredSigin.promise)
};
stateMock = jasmine.creatSpyObj('$state spy', ['go']);
controller = $controller('SiginController', {
'$state': stateMock,
'signinService': signinServiceMock
});
}));
我的应用程序根目录中有unit-test.conf.js,文件路径配置如图所示
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'www/lib/angular/angular.min.js',
'www/lib/angular-mocks/angular-mocks.js',
'www/app.js',
'www/signin/services/*.js',
'www/signin/*.js',
'www/signin/tests/*.js'
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity
});
};
我关注this tutorial。似乎角嘲讽似乎没有被装载。不知道为什么。我将它传递给unit-test.conf.js中的文件