2018-08-31 11:06:39 +00:00
|
|
|
describe('factory vnModuleLoader', () => {
|
|
|
|
let vnModuleLoader;
|
|
|
|
let $scope;
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2018-08-31 11:06:39 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject((_vnModuleLoader_, $rootScope) => {
|
2018-08-31 11:06:39 +00:00
|
|
|
vnModuleLoader = _vnModuleLoader_;
|
|
|
|
$scope = $rootScope;
|
|
|
|
}));
|
|
|
|
|
|
|
|
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: () => {}})
|
2018-12-22 10:59:26 +00:00
|
|
|
.then(() => {
|
|
|
|
done.fail('this must fail');
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
expect(error.toString()).toEqual(`Error: Module dependency loop detected: myModule`);
|
|
|
|
done();
|
|
|
|
});
|
2018-08-31 11:06:39 +00:00
|
|
|
$scope.$apply();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|