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

extend() does not recursively deep copy #5

Open
agmcleod opened this issue Dec 10, 2015 · 0 comments
Open

extend() does not recursively deep copy #5

agmcleod opened this issue Dec 10, 2015 · 0 comments

Comments

@agmcleod
Copy link

Something that recently bit me, was we use a serialized json coloumn on a number of our backend models. So to replicate that in the front end, we have a number of factories like this:

chai.factory('user', {
  id: 1,
  name: 'user1',
  data: {},
});

The data column will then be used in various specs. Because of the way extend works, the collection map holds on to the default factory that contains a reference to data. As new factories are created, that same data in memory gets updated instead of replaced with a fresh object.

One potential solution is to update it to do a recursive clone, something like this: http://stackoverflow.com/a/728694/645132. Where it checks the typs, either does a return or creates a new object/array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant