-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
246 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
**/.* | ||
examples/ | ||
src/ | ||
tests/ | ||
bower.json | ||
changelog.js | ||
gulpfile.js | ||
validate-commit-msg.js | ||
karma.conf.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module.exports = function(config) { | ||
config.set(module.exports.conf); | ||
}; | ||
|
||
module.exports.conf = { | ||
|
||
// 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'], | ||
|
||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
'bower_components/angular/angular.js', | ||
'bower_components/angular-mocks/angular-mocks.js', | ||
'src/**/*.js', | ||
'tests/unit/**/*.spec.js', | ||
'tests/unit/**/*.mock.js' | ||
], | ||
|
||
|
||
// list of files to exclude | ||
exclude: [], | ||
|
||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
'src/ocLazyLoad.js': ['coverage'] | ||
}, | ||
|
||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['progress', 'coverage'], | ||
|
||
|
||
// web server port | ||
port: 9876, | ||
|
||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
|
||
// 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: ['Chrome'], | ||
|
||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: false | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
document.querySelector('html').setAttribute('ng-app','app1'); | ||
|
||
angular.module('app1', ['oc.lazyLoad']) | ||
.config(['$ocLazyLoadProvider', function($ocLazyLoadProvider) { | ||
$ocLazyLoadProvider.config({ | ||
modules: [{ | ||
name: 'test', | ||
files: [] | ||
}] | ||
}) | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*globals describe, beforeEach, afterEach, inject, module, it, expect, angular */ | ||
describe('Module: oc.lazyLoad', function() { | ||
'use strict'; | ||
|
||
var $ocLazyLoad; | ||
|
||
describe('with app1', function() { | ||
|
||
beforeEach(function() { | ||
module('app1'); | ||
|
||
inject(function(_$ocLazyLoad_) { | ||
$ocLazyLoad = _$ocLazyLoad_; | ||
}); | ||
}); | ||
|
||
it('service should be defined', function() { | ||
expect($ocLazyLoad).toBeDefined(); | ||
}); | ||
|
||
it('getModules should be working', function() { | ||
expect($ocLazyLoad.getModules).toBeDefined(); | ||
expect(angular.isArray($ocLazyLoad.getModules())).toBe(true); | ||
}); | ||
|
||
it('loadedModules should be working', function() { | ||
expect($ocLazyLoad.getModules()).toEqual(['ng', 'app1', 'oc.lazyLoad']); | ||
}); | ||
|
||
it('isLoaded should be working', function() { | ||
expect($ocLazyLoad.isLoaded).toBeDefined(); | ||
expect($ocLazyLoad.isLoaded).toThrowError('You need to define the module(s) name(s)'); | ||
expect($ocLazyLoad.isLoaded('app1')).toBe(true); // string arg | ||
expect($ocLazyLoad.isLoaded(['ng', 'app1'])).toBe(true); // array arg | ||
expect($ocLazyLoad.isLoaded('noModule')).toBe(false); | ||
expect($ocLazyLoad.isLoaded(['ng', 'noModule'])).toBe(false); | ||
}); | ||
|
||
it('getModuleConfig should be working', function() { | ||
expect($ocLazyLoad.getModuleConfig).toBeDefined(); | ||
expect($ocLazyLoad.getModuleConfig).toThrowError('You need to give the name of the module to get'); | ||
expect($ocLazyLoad.getModuleConfig('noModule')).toBe(null); | ||
expect($ocLazyLoad.getModuleConfig('test')).toEqual({name: 'test', files: []}); | ||
}); | ||
|
||
it('setModuleConfig should be working', function() { | ||
expect($ocLazyLoad.setModuleConfig).toBeDefined(); | ||
expect($ocLazyLoad.setModuleConfig).toThrowError('You need to give the module config object to set'); | ||
expect($ocLazyLoad.setModuleConfig({name: 'test2'})).toEqual({name: 'test2'}); | ||
expect($ocLazyLoad.getModuleConfig('test2')).toEqual({name: 'test2'}); // check if set worked | ||
}); | ||
|
||
}); | ||
|
||
describe('failed configs', function() { | ||
|
||
it('should throw an error if js loader is not a function', function() { | ||
expect(function() { | ||
angular.module('app2', ['oc.lazyLoad']) | ||
.config(['$ocLazyLoadProvider', function($ocLazyLoadProvider) { | ||
$ocLazyLoadProvider.config({ | ||
jsLoader: '' | ||
}); | ||
}]); | ||
module('app2'); | ||
inject(function(_$ocLazyLoad_) {}); | ||
}).toThrowError(/The js loader needs to be a function/); | ||
}); | ||
|
||
it('should throw an error if css loader is not a function', function() { | ||
expect(function() { | ||
angular.module('app2', ['oc.lazyLoad']) | ||
.config(['$ocLazyLoadProvider', function($ocLazyLoadProvider) { | ||
$ocLazyLoadProvider.config({ | ||
cssLoader: '' | ||
}); | ||
}]); | ||
module('app2'); | ||
inject(function(_$ocLazyLoad_) {}); | ||
}).toThrowError(/The css loader needs to be a function/); | ||
}); | ||
|
||
it('should throw an error if css loader is not a function', function() { | ||
expect(function() { | ||
angular.module('app2', ['oc.lazyLoad']) | ||
.config(['$ocLazyLoadProvider', function($ocLazyLoadProvider) { | ||
$ocLazyLoadProvider.config({ | ||
templatesLoader: '' | ||
}); | ||
}]); | ||
module('app2'); | ||
inject(function(_$ocLazyLoad_) {}); | ||
}).toThrowError(/The template loader needs to be a function/); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters