-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: arrow & static class methods as adapter factories (#1197)
Co-authored-by: Filip Skokan <panva.ip@gmail.com>
- Loading branch information
1 parent
994697d
commit cee552f
Showing
7 changed files
with
132 additions
and
8 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,12 @@ | ||
const hasPrototype = (target) => target.prototype !== null && typeof target.prototype === 'object'; | ||
|
||
const isContructor = (fn) => fn.constructor instanceof Function | ||
&& fn.constructor.name !== undefined; | ||
|
||
const isConstructable = (constructable) => constructable instanceof Function | ||
&& hasPrototype(constructable) | ||
&& isContructor(constructable.constructor); | ||
|
||
module.exports = { | ||
isConstructable, | ||
}; |
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
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,19 @@ | ||
/* eslint-disable prefer-arrow-callback */ | ||
const { expect } = require('chai'); | ||
|
||
const { isConstructable } = require('../../lib/helpers/type_validators'); | ||
|
||
describe('type validators helper', () => { | ||
it('should be falsy when argument is null', () => { | ||
expect(isConstructable(null)).to.be.false; | ||
}); | ||
|
||
it('should be falsy when argument is arrow function', () => { | ||
expect(isConstructable(() => {})).to.be.false; | ||
}); | ||
|
||
it('should be successfull executed if argument is constructable', () => { | ||
expect(isConstructable(class {})).to.be.true; | ||
expect(isConstructable(function () {})).to.be.true; | ||
}); | ||
}); |
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