|
1 | 1 | import { Reflection as Reflect } from './index'; |
2 | 2 |
|
| 3 | +const metadataKey = 'key'; |
| 4 | +const metadataValue = 'value'; |
| 5 | +const target = {}; |
| 6 | + |
3 | 7 | test('with invalid target', () => { |
4 | | - const metadataKey = 'key'; |
5 | | - const metadataValue = 'value'; |
6 | 8 | expect(() => Reflect.defineMetadata(metadataKey, metadataValue)).toThrow(TypeError); |
7 | 9 | }); |
8 | 10 |
|
9 | 11 | test('with target but no property key', () => { |
10 | | - const metadataKey = 'key'; |
11 | | - const metadataValue = 'value'; |
12 | | - const target = {}; |
13 | 12 | expect(() => Reflect.defineMetadata(metadataKey, metadataValue, target)).not.toThrow(); |
14 | 13 | }); |
15 | 14 |
|
16 | 15 | test('with target and property key', () => { |
17 | | - const metadataKey = 'key'; |
18 | | - const metadataValue = 'value'; |
19 | | - const target = {}; |
20 | 16 | const propertyKey = 'name'; |
21 | 17 | expect(() => Reflect.defineMetadata(metadataKey, metadataValue, target, propertyKey)).not.toThrow(); |
22 | 18 | }); |
| 19 | + |
| 20 | +test('metadata map is reused', () => { |
| 21 | + const metadataKey2 = 'key2'; |
| 22 | + const metadataValue2 = 'value2'; |
| 23 | + Reflect.defineMetadata(metadataKey, metadataValue, target); |
| 24 | + Reflect.defineMetadata(metadataKey2, metadataValue2, target); |
| 25 | + expect(Reflect.getOwnMetadata(metadataKey, target)).toEqual(metadataValue); |
| 26 | + expect(Reflect.getOwnMetadata(metadataKey2, target)).toEqual(metadataValue2); |
| 27 | +}); |
0 commit comments