-
-
Notifications
You must be signed in to change notification settings - Fork 15
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 #8 from abraham/fix-define
Fix metadata map getting recreated
- Loading branch information
Showing
3 changed files
with
15 additions
and
9 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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import { Reflection as Reflect } from './index'; | ||
|
||
const metadataKey = 'key'; | ||
const metadataValue = 'value'; | ||
const target = {}; | ||
|
||
test('with invalid target', () => { | ||
const metadataKey = 'key'; | ||
const metadataValue = 'value'; | ||
expect(() => Reflect.defineMetadata(metadataKey, metadataValue)).toThrow(TypeError); | ||
}); | ||
|
||
test('with target but no property key', () => { | ||
const metadataKey = 'key'; | ||
const metadataValue = 'value'; | ||
const target = {}; | ||
expect(() => Reflect.defineMetadata(metadataKey, metadataValue, target)).not.toThrow(); | ||
}); | ||
|
||
test('with target and property key', () => { | ||
const metadataKey = 'key'; | ||
const metadataValue = 'value'; | ||
const target = {}; | ||
const propertyKey = 'name'; | ||
expect(() => Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey)).not.toThrow(); | ||
}); | ||
|
||
test('metadata map is reused', () => { | ||
const metadataKey2 = 'key2'; | ||
const metadataValue2 = 'value2'; | ||
Reflect.defineMetadata(metadataKey, metadataValue, target); | ||
Reflect.defineMetadata(metadataKey2, metadataValue2, target); | ||
expect(Reflect.getOwnMetadata(metadataKey, target)).toEqual(metadataValue); | ||
expect(Reflect.getOwnMetadata(metadataKey2, target)).toEqual(metadataValue2); | ||
}); |
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