-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes linting errors due to injectors being added at runtime
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as module from './module'; | ||
import { ModuleLoader } from './module.loader'; | ||
|
||
describe('ModuleLoader', () => { | ||
describe('getController', () => { | ||
it('should throw error if module given is invalid', () => { | ||
jest.spyOn(module, 'isModule').mockReturnValue(false); | ||
|
||
class InvalidModule {} | ||
class WantedController {} | ||
|
||
const handler = () => { | ||
ModuleLoader.getController(InvalidModule, WantedController); | ||
}; | ||
|
||
expect(handler).toThrow(TypeError); | ||
}); | ||
|
||
it('should get controller from module', () => { | ||
jest.spyOn(module, 'isModule').mockReturnValue(true); | ||
|
||
const mockController = jest.fn(); | ||
|
||
class WantedController {} | ||
class Module { | ||
static getController() { | ||
return mockController; | ||
} | ||
} | ||
|
||
const controller = ModuleLoader.getController(Module, WantedController); | ||
|
||
expect(controller).toBe(mockController); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
import { isModule } from './module'; | ||
|
||
export class ModuleLoader { | ||
static getController<T>(module: any, controller: new (...args) => T): T { | ||
if (!isModule(module)) { | ||
throw new TypeError('Invalid Module'); | ||
} | ||
|
||
return module.getController(controller); | ||
} | ||
} |
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