Skip to content

Commit

Permalink
refactor(core): add isPendingClassMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
notaphplover committed Dec 15, 2024
1 parent 75b972d commit 6b45701
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { beforeAll, describe, expect, it } from '@jest/globals';

import 'reflect-metadata';

import { pendingClassMetadataCountReflectKey } from '../../reflectMetadata/data/pendingClassMetadataCountReflectKey';
import { isPendingClassMetadata } from './isPendingClassMetadata';

describe(isPendingClassMetadata.name, () => {
describe('having no metadata', () => {
describe('when called', () => {
let result: unknown;

beforeAll(() => {
result = isPendingClassMetadata(class {});
});

it('should return false', () => {
expect(result).toBe(false);
});
});
});

describe('having non zero number as metadata', () => {
describe('when called', () => {
class Foo {}

let result: unknown;

beforeAll(() => {
Reflect.defineMetadata(pendingClassMetadataCountReflectKey, 1, Foo);

result = isPendingClassMetadata(Foo);
});

it('should return true', () => {
expect(result).toBe(true);
});
});
});

describe('having zero number as metadata', () => {
describe('when called', () => {
class Foo {}

let result: unknown;

beforeAll(() => {
Reflect.defineMetadata(pendingClassMetadataCountReflectKey, 0, Foo);

result = isPendingClassMetadata(Foo);
});

it('should return false', () => {
expect(result).toBe(false);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Newable } from '@inversifyjs/common';
import { getReflectMetadata } from '@inversifyjs/reflect-metadata-utils';

import { pendingClassMetadataCountReflectKey } from '../../reflectMetadata/data/pendingClassMetadataCountReflectKey';

export function isPendingClassMetadata(type: Newable): boolean {
const pendingClassMetadataCount: number | undefined = getReflectMetadata(
type,
pendingClassMetadataCountReflectKey,
);

return (
pendingClassMetadataCount !== undefined && pendingClassMetadataCount !== 0
);
}

0 comments on commit 6b45701

Please sign in to comment.