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

Modifying loaded fixture data permanently modifies fixture data #12

Closed
jamesbrobb opened this issue Jan 25, 2016 · 2 comments
Closed

Modifying loaded fixture data permanently modifies fixture data #12

jamesbrobb opened this issue Jan 25, 2016 · 2 comments

Comments

@jamesbrobb
Copy link

I have a beforeEach that loads a fixture and then several it statements that use that data to create a model.

The logic i'm testing modifies the mock data object that's created by the fixture load and i've noticed that this modification persists from one it to the next. I've tried using cleanup() in an afterEach but it makes no difference.

I'm presuming that once the json fixture is loaded it's cached as an object and that same objects is returned. So any modification to that object then persists. Unless i'm doing something wrong?

describe('my test', function() {

    var mockData;

    function changeSomeValueToB(data) {
        data.someValue = 'B';
    }

    beforeEach(function() {
        mockData = fixture.load('my/mock/data.fixture.json');
    });

    afterEach(function() {
        fixture.cleanUp();
    });

    it('should do something', function() {
        expect(mockData.someValue).toBe('A'); // passes
        changeSomeValueToB(mockData);
    });

    it('should do something else', function() {
        expect(mockData.someValue).toBe('A'); // fails
        expect(mockData.someValue).toBe('B'); // passes
    });
});
@nzakas
Copy link
Collaborator

nzakas commented Jan 25, 2016

It looks like the code is relying on json-fixtures for the JSON loading functionality, and it appears that json-fixtures caches data each time.

@billtrik
Copy link
Owner

Hello @jamesbrobb
You can find the fix in the latest version of the plugin. (0.2.6)

Good catch by the way.

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

4 participants
@nzakas @billtrik @jamesbrobb and others