Skip to content

Commit

Permalink
instances created via "child" method can also have a name
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandotv committed Mar 18, 2024
1 parent 99aaca2 commit 61a361f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-kangaroos-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pumpit": patch
---

instances created via "child" method can also have a name
7 changes: 7 additions & 0 deletions src/__tests__/pumpit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,12 @@ describe("Optional injection", () => {

expect(pumpIt.getName()).toBe(undefined)
})

test("instance created via child can also have a name", () => {
const name = "instance_name"
const pumpIt = new PumpIt()
const child = pumpIt.child(name)
expect(child.getName()).toBe(name)
})
})
})
4 changes: 2 additions & 2 deletions src/pumpit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ export class PumpIt {
* parent singleton values.
*
*/
child(): this {
const child = new (this.constructor as new () => this)()
child(name?: string): this {
const child = new (this.constructor as new (name?: string) => this)(name)
child.parent = this

return child
Expand Down

0 comments on commit 61a361f

Please sign in to comment.