-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from abraham/get-own-metadata
Add getOwnMetadata
- Loading branch information
Showing
4 changed files
with
52 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
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,41 @@ | ||
import { Reflection as Reflect } from './index'; | ||
|
||
const prototype = {}; | ||
const metadataKey = 'key'; | ||
const metadataValue = 'value'; | ||
const target = {}; | ||
const propertyKey = 'name'; | ||
|
||
test('invalid target', () => { | ||
expect(() => Reflect.getOwnMetadata(metadataKey)).toThrow(TypeError); | ||
}); | ||
|
||
test('not defined with target', () => { | ||
expect(Reflect.getOwnMetadata(metadataKey, target)).toBeUndefined(); | ||
}); | ||
|
||
test('defined', () => { | ||
Reflect.defineMetadata(metadataKey, metadataValue, target); | ||
expect(Reflect.getOwnMetadata(metadataKey, target)).toEqual(metadataValue); | ||
}); | ||
|
||
test('defined on prototype', () => { | ||
const target = Object.create(prototype); | ||
Reflect.defineMetadata(metadataKey, metadataValue, prototype); | ||
expect(Reflect.getOwnMetadata(metadataKey, target)).toBeUndefined(); | ||
}); | ||
|
||
test('not defined with property key', () => { | ||
expect(Reflect.getOwnMetadata(metadataKey, target, propertyKey)).toBeUndefined(); | ||
}); | ||
|
||
test('defined with property key', () => { | ||
Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey); | ||
expect(Reflect.getOwnMetadata(metadataKey, target, propertyKey)).toEqual(metadataValue); | ||
}); | ||
|
||
test('defined on prototype with property key', () => { | ||
const target = Object.create(prototype); | ||
Reflect.defineMetadata(metadataKey, metadataValue, prototype, propertyKey); | ||
expect(Reflect.getOwnMetadata(metadataKey, target, propertyKey)).toBeUndefined(); | ||
}); |
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