Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error When Cloning ValueObject #152

Closed
4lessandrodev opened this issue May 1, 2024 · 0 comments · Fixed by #154
Closed

Error When Cloning ValueObject #152

4lessandrodev opened this issue May 1, 2024 · 0 comments · Fixed by #154
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@4lessandrodev
Copy link
Owner

Description:

When a ValueObject is cloned using the clone() method, the value of the cloned object is not properly maintained. When attempting to access the value using the get('value') method, the return is null instead of the original value.

Steps to Reproduce:

  • Import the Branch class from a module containing the ValueObject class.
  • Create an instance of Branch using the static method init() and assign it to a variable main.
  • Clone the main instance using the clone() method and assign it to a variable copy.
  • Attempt to access the value of the main and copy instances using the get('value') method.
  • Observe that the returned value for the copy instance is null, whereas it should be the same value as the main instance.

Expected Behavior:

The clone() method should create an exact copy of the ValueObject, keeping the original value intact. Therefore, when accessing the value using the get('value') method on the cloned instance (copy), the returned value should be the same as on the original instance (main).

Observed Behavior:

After cloning the ValueObject, the value returned when accessing get('value') on the cloned instance is null, instead of maintaining the original value.

Environment:

Language: TypeScript
Framework/Dependency: rich-domain (version v1.23.0)
Operating System: linux
Browser/Platform: nodejs v20

Sample Code:

import { ValueObject } from 'rich-domain';

class Branch extends ValueObject<string>{
    private constructor(value: string){
        super(value);
    }

    public static init(value: string): Branch {
        return new Branch(value);
    }
}

const main = Branch.init('main'); // props: 'main'
const copy = main.clone(); // props: { '0': 'm', '1': 'a', '2': 'i', '3': 'n' }

console.log(main.get('value')); // main
console.log(copy.get('value')); // null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant