Skip to content

extend() does not recursively deep copy #5

@agmcleod

Description

@agmcleod

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions