У меня есть приложение с угловыми углами с простым испытанием на карма и очень простая конфигурация с использованием requirejs и Angular 1.2.28. Мой тест в порядке.ngStorage, нарушающий мои тесты приложений
/**
* Created by jose on 7/12/2015.
*/
/*global module, inject */
define(['home', 'angularMocks','ngStorage'], function(app) {
'use strict';
describe('homeController', function() {
var scope, $location, createController;
beforeEach(module('homeApp'));
beforeEach(inject(function ($rootScope, $controller, _$location_) {
$location = _$location_;
scope = $rootScope.$new();
createController = function() {
return $controller('homeController', {
'$scope': scope
});
};
}));
it('should have message', function() {
var controller = createController();
$location.path('/');
expect($location.path()).toBe('/');
expect(scope.message).toEqual('This is Add new order screen');
});
});
});
Мой модуль:
/**
* Created by jose on 7/12/2015.
*/
'use strict';
define(['angular', 'angularRoute'], function(angular) {
var app = angular.module('homeApp', ['ngRoute']);
app.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/home.html',
controller: 'homeController'
})
.when('/404', {
templateUrl: 'partials/404.html',
})
.otherwise({
redirectTo: '/404'
});
}
]);
app.controller('homeController', function ($scope) {
$scope.message = 'This is Add new order screen';
});
return app;
});
К сожалению, когда я пытаюсь добавить ngStorage как зависимость этого модуля, он может не работает больше. Даже пытаться добавить ngStorage к моему рейзу конфигурации кармы ошибки, как это:
Error: Mismatched anonymous define() module: function (app) {
Это происходит только тогда, когда я пытаюсь использовать ngStorage, когда я просто закомментируйте его в мою ошибку karma.conf файла исчезает, и все работает отлично. .. В случае невозможности использования ngStorage with Karma существуют другие альтернативы для ngStorage? благодаря
karma.conf
// Karma configuration
// Generated on Mon Jul 13 2015 09:49:28 GMT-0300 (Hora est. Sudamérica Pacífico)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],
// list of files/patterns to load in the browser
files: [
'test-main.js',
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-route/angular-route.js',
'bower_components/ngstorage/ngStorage.js',
{pattern: 'javascripts/*.js', included: false},
{pattern: 'test/**/*Spec.js', included: false}
],
// list of files to exclude
exclude: [
'javascripts/config.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable/disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// enable/disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
Проект на GitHub: https://github.com/jbarros35/node/tree/master/angulartemplate
Уважением.
Собственные модули OP - это надлежащие модули AMD: они используют 'define'. Когда модуль использует 'define', вы ** не должны ** устанавливать для него' shim'. Поэтому ошибочно сообщать OP использовать 'define' с модулями OP. – Louis
Если вы не используете прокладку, то как вы собираетесь давать зависимости? –
Зависимости даются вызову 'define'. – Louis