-
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.
refactor(core): add isPendingClassMetadata
- Loading branch information
1 parent
75b972d
commit 6b45701
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/container/libraries/core/src/metadata/calculations/isPendingClassMetadata.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,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); | ||
}); | ||
}); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/container/libraries/core/src/metadata/calculations/isPendingClassMetadata.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,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 | ||
); | ||
} |