-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dfff5a
commit 4e6978d
Showing
3 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
packages/container/libraries/core/src/metadata/decorators/named.int.spec.ts
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,84 @@ | ||
import { beforeAll, describe, expect, it } from '@jest/globals'; | ||
|
||
import 'reflect-metadata'; | ||
|
||
import { getReflectMetadata } from '@inversifyjs/reflect-metadata-utils'; | ||
|
||
import { classMetadataReflectKey } from '../../reflectMetadata/data/classMetadataReflectKey'; | ||
import { MaybeClassElementMetadataKind } from '../models/MaybeClassElementMetadataKind'; | ||
import { MaybeClassMetadata } from '../models/MaybeClassMetadata'; | ||
import { named } from './named'; | ||
|
||
describe(named.name, () => { | ||
describe('when called', () => { | ||
let result: unknown; | ||
|
||
beforeAll(() => { | ||
class Foo { | ||
@named('bar') | ||
public readonly bar!: string; | ||
|
||
@named('baz') | ||
public readonly baz!: string; | ||
|
||
constructor( | ||
@named('firstParam') | ||
public firstParam: number, | ||
@named('secondParam') | ||
public secondParam: number, | ||
) {} | ||
} | ||
|
||
result = getReflectMetadata(Foo, classMetadataReflectKey); | ||
}); | ||
|
||
it('should return expected metadata', () => { | ||
const expected: MaybeClassMetadata = { | ||
constructorArguments: [ | ||
{ | ||
kind: MaybeClassElementMetadataKind.unknown, | ||
name: 'firstParam', | ||
optional: false, | ||
tags: new Map(), | ||
targetName: undefined, | ||
}, | ||
{ | ||
kind: MaybeClassElementMetadataKind.unknown, | ||
name: 'secondParam', | ||
optional: false, | ||
tags: new Map(), | ||
targetName: undefined, | ||
}, | ||
], | ||
lifecycle: { | ||
postConstructMethodName: undefined, | ||
preDestroyMethodName: undefined, | ||
}, | ||
properties: new Map([ | ||
[ | ||
'bar', | ||
{ | ||
kind: MaybeClassElementMetadataKind.unknown, | ||
name: 'bar', | ||
optional: false, | ||
tags: new Map(), | ||
targetName: undefined, | ||
}, | ||
], | ||
[ | ||
'baz', | ||
{ | ||
kind: MaybeClassElementMetadataKind.unknown, | ||
name: 'baz', | ||
optional: false, | ||
tags: new Map(), | ||
targetName: undefined, | ||
}, | ||
], | ||
]), | ||
}; | ||
|
||
expect(result).toStrictEqual(expected); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.