Skip to content

Commit

Permalink
refactor(core): add named decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
notaphplover committed Nov 16, 2024
1 parent 4dfff5a commit 4e6978d
Show file tree
Hide file tree
Showing 3 changed files with 462 additions and 0 deletions.
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);
});
});
});
Loading

0 comments on commit 4e6978d

Please sign in to comment.