Skip to content

Commit

Permalink
Merge pull request #63 from inversify/fix/update-lazy-service-identif…
Browse files Browse the repository at this point in the history
…ier-is-to-accept-nullish-values

Update LazyServiceIdentifier.is to support nullish values
  • Loading branch information
notaphplover authored Nov 1, 2024
2 parents f0b6410 + cb8882f commit 36fc6ea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-waves-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/common": patch
---

Updated LazyServiceIdentifier.is to support nullish values
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,46 @@ describe(LazyServiceIdentifier.name, () => {
});

describe('.is', () => {
describe('having a non object', () => {
let valueFixture: unknown;

beforeAll(() => {
valueFixture = Symbol();
});

describe('when called', () => {
let result: unknown;

beforeAll(() => {
result = LazyServiceIdentifier.is(valueFixture);
});

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

describe('having a null object', () => {
let valueFixture: null;

beforeAll(() => {
valueFixture = null;
});

describe('when called', () => {
let result: unknown;

beforeAll(() => {
result = LazyServiceIdentifier.is(valueFixture);
});

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

describe('having an object with islazyServiceIdentifierSymbol property', () => {
let valueFixture: LazyServiceIdentifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class LazyServiceIdentifier<TInstance = unknown> {
value: unknown,
): value is LazyServiceIdentifier<TInstance> {
return (
typeof value === 'object' &&
value !== null &&
(value as Partial<LazyServiceIdentifier>)[
islazyServiceIdentifierSymbol
] === true
Expand Down

0 comments on commit 36fc6ea

Please sign in to comment.