#497 module-loader.js Front unit test
This commit is contained in:
parent
bc2554e6f9
commit
25ac0db1cb
|
@ -15,8 +15,7 @@ export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $t
|
|||
if (loaded[moduleName] instanceof Promise)
|
||||
return loaded[moduleName];
|
||||
if (loaded[moduleName] === false)
|
||||
return $q.reject(
|
||||
new Error(`Module dependency loop detected: ${moduleName}`));
|
||||
return $q.reject(new Error(`Module dependency loop detected: ${moduleName}`));
|
||||
|
||||
loaded[moduleName] = false;
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
describe('factory vnModuleLoader', () => {
|
||||
let vnModuleLoader;
|
||||
let $scope;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('vnCore');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_vnModuleLoader_, $rootScope, $httpBackend) => {
|
||||
vnModuleLoader = _vnModuleLoader_;
|
||||
$scope = $rootScope;
|
||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
}));
|
||||
|
||||
describe('load()', () => {
|
||||
it('should return truthy promise if the module was loaded', async() => {
|
||||
vnModuleLoader._loaded.myModule = true;
|
||||
|
||||
let result = await vnModuleLoader.load('myModule', {myValidations: () => {}});
|
||||
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return a promise if the module was still a promise', () => {
|
||||
vnModuleLoader._loaded.myModule = new Promise(() => {
|
||||
return 'I promise you a module!';
|
||||
});
|
||||
|
||||
let result = vnModuleLoader.load('myModule', {myValidations: () => {}});
|
||||
|
||||
expect(result).toEqual(jasmine.any(Promise));
|
||||
});
|
||||
|
||||
it('should return an error if the module wasnt loaded', done => {
|
||||
vnModuleLoader._loaded.myModule = false;
|
||||
|
||||
vnModuleLoader.load('myModule', {myValidations: () => {}})
|
||||
.then(() => {
|
||||
done.fail('this must fail');
|
||||
})
|
||||
.catch(error => {
|
||||
expect(error.toString()).toEqual(`Error: Module dependency loop detected: myModule`);
|
||||
done();
|
||||
});
|
||||
$scope.$apply();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue