Skip to content

Commit

Permalink
Change sandbox naming to be more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
TzviPM committed Aug 7, 2018
1 parent 922012c commit ff5c0fb
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions docs/installation/mount-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Adapter from 'enzyme-adapter-react-16';

configure({
adapter: new Adapter(),
enableMountTracking: true,
enableSandbox: true,
});
```

Expand All @@ -39,7 +39,7 @@ var Adapter = require('enzyme-adapter-react-16');

enzyme.configure({
adapter: new Adapter(),
enableMountTracking: true,
enableSandbox: true,
});
```

Expand Down
10 changes: 5 additions & 5 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
sym,
getAdapter,
} from 'enzyme/build/Utils';
import * as mountTracking from 'enzyme/build/mountTracking';
import * as wrapperSandbox from 'enzyme/build/wrapperSandbox';

import './_helpers/setupAdapters';
import {
Expand Down Expand Up @@ -81,13 +81,13 @@ describeWithDOM('mount', () => {
expect(spy).to.have.property('callCount', 1);
});

it('should call trackMountedWrapper', () => {
it('should call trackWrapper', () => {
const spy = sinon.spy();
const originalTrackMountedWrapper = mountTracking.trackMountedWrapper;
mountTracking.trackMountedWrapper = spy;
const originalTrackWrapper = wrapperSandbox.trackWrapper;
wrapperSandbox.trackWrapper = spy;
mount(<p>foo</p>);
expect(spy).to.have.property('callCount', 1);
mountTracking.trackMountedWrapper = originalTrackMountedWrapper;
wrapperSandbox.trackWrapper = originalTrackWrapper;
});
});

Expand Down
10 changes: 5 additions & 5 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
sym,
getAdapter,
} from 'enzyme/build/Utils';
import * as mountTracking from 'enzyme/build/mountTracking';
import * as wrapperSandbox from 'enzyme/build/wrapperSandbox';

import './_helpers/setupAdapters';
import { createClass, createContext } from './_helpers/react-compat';
Expand Down Expand Up @@ -73,13 +73,13 @@ describe('shallow', () => {
expect(wrapper.children().props().bam).to.equal(undefined);
});

it('should call trackMountedWrapper', () => {
it('should call trackWrapper', () => {
const spy = sinon.spy();
const originalTrackMountedWrapper = mountTracking.trackMountedWrapper;
mountTracking.trackMountedWrapper = spy;
const originalTrackWrapper = wrapperSandbox.trackWrapper;
wrapperSandbox.trackWrapper = spy;
shallow(<p>foo</p>);
expect(spy).to.have.property('callCount', 1);
mountTracking.trackMountedWrapper = originalTrackMountedWrapper;
wrapperSandbox.trackWrapper = originalTrackWrapper;
});
});

Expand Down
12 changes: 6 additions & 6 deletions packages/enzyme-test-suite/test/mountTracking-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { ReactWrapper, configure } from 'enzyme';
import { get } from 'enzyme/build/configuration';

import {
trackMountedWrapper,
trackWrapper,
unmountAllWrappers,
} from 'enzyme/build/mountTracking';
} from 'enzyme/build/wrapperSandbox';

const originalConfig = get();

describe('mountTracking', () => {
describe('wrapperSandbox', () => {
afterEach(() => {
configure(originalConfig);
});
Expand All @@ -21,13 +21,13 @@ describe('mountTracking', () => {
const spy = sinon.spy();
wrapper.unmount = spy;

trackMountedWrapper(wrapper);
trackWrapper(wrapper);
unmountAllWrappers();
// default configuration is not to track wrappers
expect(spy).to.have.property('callCount', 0);

configure({ enableMountTracking: true });
trackMountedWrapper(wrapper);
configure({ enableSandbox: true });
trackWrapper(wrapper);
unmountAllWrappers();
// default configuration is not to track wrappers
expect(spy).to.have.property('callCount', 1);
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mount from './mount';
import shallow from './shallow';
import render from './render';
import { merge as configure } from './configuration';
import { trackMountedWrapper, unmountAllWrappers } from './mountTracking';
import { trackWrapper, unmountAllWrappers } from './wrapperSandbox';

module.exports = {
render,
Expand All @@ -16,6 +16,6 @@ module.exports = {
ReactWrapper,
configure,
EnzymeAdapter,
trackMountedWrapper,
trackWrapper,
unmountAllWrappers,
};
4 changes: 2 additions & 2 deletions packages/enzyme/src/mount.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReactWrapper from './ReactWrapper';
import { trackMountedWrapper } from './mountTracking';
import { trackWrapper } from './wrapperSandbox';

/**
* Mounts and renders a react component into the document and provides a testing wrapper around it.
Expand All @@ -9,6 +9,6 @@ import { trackMountedWrapper } from './mountTracking';
*/
export default function mount(node, options) {
const wrapper = new ReactWrapper(node, null, options);
trackMountedWrapper(wrapper);
trackWrapper(wrapper);
return wrapper;
}
4 changes: 2 additions & 2 deletions packages/enzyme/src/shallow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ShallowWrapper from './ShallowWrapper';
import { trackMountedWrapper } from './mountTracking';
import { trackWrapper } from './wrapperSandbox';

/**
* Shallow renders a react component and provides a testing wrapper around it.
Expand All @@ -9,6 +9,6 @@ import { trackMountedWrapper } from './mountTracking';
*/
export default function shallow(node, options) {
const wrapper = new ShallowWrapper(node, null, options);
trackMountedWrapper(wrapper);
trackWrapper(wrapper);
return wrapper;
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { get } from './configuration';

const mountedWrappers = new Set();
const wrappers = new Set();

/**
* Stores a reference to a testing wrapper for later unmounting
* via unmountAllWrappers()
*
* @param {ReactWrapper|ShallowWrapper} wrapper
*/
export function trackMountedWrapper(wrapper) {
const { enableMountTracking } = get();
if (enableMountTracking) {
mountedWrappers.add(wrapper);
export function trackWrapper(wrapper) {
const { enableSandbox } = get();
if (enableSandbox) {
wrappers.add(wrapper);
}
}

/**
* Unmounts all actively mounted Enzyme wrappers.
* Unmounts all sandboxed Enzyme wrappers.
*
* Usually, this can be run once for an entire test suite after all each test
* (and its nested hooks)have been run. However, in some cases this may need
Expand All @@ -26,6 +26,6 @@ export function trackMountedWrapper(wrapper) {
* identifiers being invalid.
*/
export function unmountAllWrappers() {
mountedWrappers.forEach(wrapper => wrapper.unmount());
mountedWrappers.clear();
wrappers.forEach(wrapper => wrapper.unmount());
wrappers.clear();
}

0 comments on commit ff5c0fb

Please sign in to comment.