-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Se asegura que AbstractController no se pueda inicializar directamente
- Loading branch information
Showing
3 changed files
with
23 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const AbstractController = require('../abstractController'); | ||
const AbstractControllerError = require('../error/abstractControllerError'); | ||
|
||
test('No se puede crear una nueva instancia de un AbstractController directamente', () => { | ||
try { | ||
// eslint-disable-next-line no-new | ||
new AbstractController(); | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(AbstractControllerError); | ||
} | ||
}); | ||
|
||
test('Se puede crear una nueva instancia de una clase que hereda de AbstractController', () => { | ||
const ConcreteController = class extends AbstractController {}; | ||
expect(new ConcreteController()).toBeInstanceOf(AbstractController); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
const AbstractControllerError = require('./error/abstractControllerError'); | ||
|
||
module.exports = class AbstractController { | ||
getSessionErrors(session) { | ||
return Array.isArray(session.errors) ? session.errors : []; | ||
constructor() { | ||
if (new.target === AbstractController) { | ||
throw new AbstractControllerError(); | ||
} | ||
} | ||
}; |
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 @@ | ||
module.exports = class AbstractControllerError extends Error {}; |