Skip to content

Commit

Permalink
Don't let changes to expect.output.preferredWidth propagate into exis…
Browse files Browse the repository at this point in the history
…ting clones
  • Loading branch information
papandreou committed Jan 2, 2019
1 parent 6ca8b50 commit 2ac944d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Unexpected.js
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,8 @@ Unexpected.prototype.clone = function() {
});
// Install the hooks:
unexpected._expect = this._expect;
// Make sure that changes to the parent's preferredWidth doesn't propagate:
unexpected.output.preferredWidth = this.output.preferredWidth;
return makeExpectFunction(unexpected);
};

Expand Down
81 changes: 81 additions & 0 deletions test/preferredWidth.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*global unexpected*/

describe('expect.output.preferredWidth', () => {
var expect = unexpected.clone();
beforeEach(() => {
expect = expect.clone();
expect.output.preferredWidth = 9999;
});

describe('and a clone', () => {
var clonedExpect;
beforeEach(() => {
clonedExpect = expect.clone();
});

it('should propagate into the clone', () => {
expect(clonedExpect.output.preferredWidth, 'to be', 9999);
});

describe('when the value is changed in the clone', () => {
beforeEach(() => {
clonedExpect.output.preferredWidth = 7777;
});

it('should not affect the original', () => {
expect(expect.output.preferredWidth, 'to be', 9999);
});
});

describe('when the value is changed in the original after the clone was made', () => {
beforeEach(() => {
expect.output.preferredWidth = 5555;
});

it('should not affect the clone', () => {
expect(clonedExpect.output.preferredWidth, 'to be', 9999);
});
});
});

describe('and a child', () => {
var childExpect;
beforeEach(() => {
childExpect = expect.child();
});

it('should propagate into the child', () => {
expect(childExpect.output.preferredWidth, 'to be', 9999);
});

describe('when the value is changed in the child', () => {
beforeEach(() => {
childExpect.output.preferredWidth = 7777;
});

it('should not affect the original', () => {
expect(expect.output.preferredWidth, 'to be', 9999);
});

describe('and then in the parent', () => {
beforeEach(() => {
expect.output.preferredWidth = 4444;
});

it('should not affect the child', () => {
expect(childExpect.output.preferredWidth, 'to be', 7777);
});
});
});

describe('when the value is changed in the original after the child was made', () => {
beforeEach(() => {
expect.output.preferredWidth = 5555;
});

it('should propagate the change to the child', () => {
expect(childExpect.output.preferredWidth, 'to be', 5555);
});
});
});
});

0 comments on commit 2ac944d

Please sign in to comment.