Skip to content

Commit

Permalink
more PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lelandrichardson committed Aug 15, 2017
1 parent bd93716 commit 6966eda
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 119 deletions.
42 changes: 20 additions & 22 deletions docs/future/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,29 @@ two elements being found.
Although this is a breaking change, I believe the new behavior is closer to what people would
actually expect and want.

## `get(n)` versus `getElement(n)` versus `getNode()`

NOTE: might be able to get rid of this

get(n) v2: returns the react element that the wrapper wraps at index n
get(n) v3: returns the RST node that the wrapper wraps at index n

getNode() v2: returns the react element that the wrapper wraps (must be single)
getNode() v3: returns the RST node that the wrapper wraps (must be single)

getElement(n) v3: effectively what `get(n)` was in v2

## `children()` now has slightly different meaning

Enzyme has a `.children()` method which is intended to return the rendered children of a wrapper.

## `children()` now has slightly different meaning
When using `mount(...)`, it can sometimes be unclear exactly what this would mean. Consider for
example the following react components:

TODO: talk about this
```js
class Box extends React.Component {
render() {
return <div className="box">{this.props.children}</div>;
}
}
class Foo extends React.Component {
render() {
return (
<Box bam>
<div className="div" />
</Box>
);
}
}
```

## For `mount`, updates are sometimes required when they weren't before

Expand Down Expand Up @@ -358,12 +364,4 @@ const wrapper = mount(<Foo outer={x} />);
expect(wrapper.props()).to.deep.equal({ outer: x });
```

## for shallow, getNode() was renamed to getElement()

## for mount, getNode() should not be used. instance() does what it used to.

## for mount, getElement() will return the root JSX element

## what getNode() returns

we need to keep in mind that `getElement()` will no longer be referentially equal to what it was before.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('babel-register');

var IgnorePlugin = require('webpack').IgnorePlugin;
var is = require('./src/version').is;
var is = require('./test/version').is;

function getPlugins() {
const adapter13 = new IgnorePlugin(/adapters\/ReactThirteenAdapter/);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
"rimraf": "^2.6.1",
"safe-publish-latest": "^1.1.1",
"sinon": "^2.4.1",
"webpack": "^1.13.3"
"webpack": "^1.13.3",
"react": "0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0"
},
"peerDependencies": {
"react": "0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0"
Expand Down
25 changes: 0 additions & 25 deletions setupAdapters.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/ReactWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ class ReactWrapper {
);
}

rendered() {
return this.single('rendered', n => this.wrap(n.rendered));
}

/**
* Returns the wrapped component.
*
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/ReactThirteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import PropTypes from 'prop-types';
import values from 'object.values';
import EnzymeAdapter from './EnzymeAdapter';
import elementToTree from './elementToTree';
import mapNativeEventNames from './ReactThirteenMapNativeEventNames'
import {
mapNativeEventNames,
propFromEvent,
withSetStateAllowed,
assertDomAvailable,
Expand Down
11 changes: 2 additions & 9 deletions src/adapters/Utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { REACT013 } from '../version';

export function mapNativeEventNames(event) {
const nativeToReactEventMap = {
compositionend: 'compositionEnd',
Expand Down Expand Up @@ -36,15 +34,10 @@ export function mapNativeEventNames(event) {
timeupdate: 'timeUpdate',
volumechange: 'volumeChange',
beforeinput: 'beforeInput',
mouseenter: 'mouseEnter',
mouseleave: 'mouseLeave',
};

if (!REACT013) {
// these could not be simulated in React 0.13:
// https://github.com/facebook/react/issues/1297
nativeToReactEventMap.mouseenter = 'mouseEnter';
nativeToReactEventMap.mouseleave = 'mouseLeave';
}

return nativeToReactEventMap[event] || event;
}

Expand Down
16 changes: 0 additions & 16 deletions src/version.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/Adapter-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '../setupAdapters';
import './setupAdapters';
import React from 'react';
import { expect } from 'chai';

import { REACT013, REACT16 } from '../src/version';
import { REACT013, REACT16 } from './version';
import configuration from '../src/configuration';
import { itIf, describeWithDOM } from './_helpers';

Expand Down
2 changes: 1 addition & 1 deletion test/ComplexSelector-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../setupAdapters';
import './setupAdapters';
import React from 'react';
import { expect } from 'chai';

Expand Down
4 changes: 2 additions & 2 deletions test/Debug-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../setupAdapters';
import './setupAdapters';
import { expect } from 'chai';
import React from 'react';
import {
Expand All @@ -13,7 +13,7 @@ import {
describeIf,
itIf,
} from './_helpers';
import { REACT013 } from '../src/version';
import { REACT013 } from './version';
import configuration from '../src/configuration';

const { adapter } = configuration.get();
Expand Down
4 changes: 2 additions & 2 deletions test/RSTTraversal-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../setupAdapters';
import './setupAdapters';
import React from 'react';
import sinon from 'sinon';
import { expect } from 'chai';
Expand All @@ -16,7 +16,7 @@ import {
buildPredicate,
} from '../src/RSTTraversal';
import { describeIf } from './_helpers';
import { REACT013 } from '../src/version';
import { REACT013 } from './version';

const $ = elementToTree;

Expand Down
56 changes: 28 additions & 28 deletions test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals document */
import '../setupAdapters';
import './setupAdapters';
import React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
Expand Down Expand Up @@ -1916,10 +1916,10 @@ describeWithDOM('mount', () => {
]}
/>,
);
expect(wrapper.rendered().children().length).to.equal(3);
expect(wrapper.rendered().children().at(0).hasClass('foo')).to.equal(true);
expect(wrapper.rendered().children().at(1).hasClass('bar')).to.equal(true);
expect(wrapper.rendered().children().at(2).hasClass('baz')).to.equal(true);
expect(wrapper.children().children().length).to.equal(3);
expect(wrapper.children().children().at(0).hasClass('foo')).to.equal(true);
expect(wrapper.children().children().at(1).hasClass('bar')).to.equal(true);
expect(wrapper.children().children().at(2).hasClass('baz')).to.equal(true);
});

it('should optionally allow a selector to filter by', () => {
Expand Down Expand Up @@ -1959,10 +1959,10 @@ describeWithDOM('mount', () => {
]}
/>,
);
expect(wrapper.rendered().children().length).to.equal(3);
expect(wrapper.rendered().children().at(0).hasClass('foo')).to.equal(true);
expect(wrapper.rendered().children().at(1).hasClass('bar')).to.equal(true);
expect(wrapper.rendered().children().at(2).hasClass('baz')).to.equal(true);
expect(wrapper.children().children().length).to.equal(3);
expect(wrapper.children().children().at(0).hasClass('foo')).to.equal(true);
expect(wrapper.children().children().at(1).hasClass('bar')).to.equal(true);
expect(wrapper.children().children().at(2).hasClass('baz')).to.equal(true);
});
});
});
Expand Down Expand Up @@ -2153,12 +2153,12 @@ describeWithDOM('mount', () => {
expect(wrapper.hasClass('FoOo')).to.equal(false);
expect(wrapper.hasClass('doesnt-exist')).to.equal(false);

expect(wrapper.rendered().hasClass('foo')).to.equal(true);
expect(wrapper.rendered().hasClass('bar')).to.equal(true);
expect(wrapper.rendered().hasClass('baz')).to.equal(true);
expect(wrapper.rendered().hasClass('some-long-string')).to.equal(true);
expect(wrapper.rendered().hasClass('FoOo')).to.equal(true);
expect(wrapper.rendered().hasClass('doesnt-exist')).to.equal(false);
expect(wrapper.children().hasClass('foo')).to.equal(true);
expect(wrapper.children().hasClass('bar')).to.equal(true);
expect(wrapper.children().hasClass('baz')).to.equal(true);
expect(wrapper.children().hasClass('some-long-string')).to.equal(true);
expect(wrapper.children().hasClass('FoOo')).to.equal(true);
expect(wrapper.children().hasClass('doesnt-exist')).to.equal(false);
});
});

Expand All @@ -2178,12 +2178,12 @@ describeWithDOM('mount', () => {
expect(wrapper.hasClass('FoOo')).to.equal(false);
expect(wrapper.hasClass('doesnt-exist')).to.equal(false);

expect(wrapper.rendered().hasClass('foo')).to.equal(true);
expect(wrapper.rendered().hasClass('bar')).to.equal(true);
expect(wrapper.rendered().hasClass('baz')).to.equal(true);
expect(wrapper.rendered().hasClass('some-long-string')).to.equal(true);
expect(wrapper.rendered().hasClass('FoOo')).to.equal(true);
expect(wrapper.rendered().hasClass('doesnt-exist')).to.equal(false);
expect(wrapper.children().hasClass('foo')).to.equal(true);
expect(wrapper.children().hasClass('bar')).to.equal(true);
expect(wrapper.children().hasClass('baz')).to.equal(true);
expect(wrapper.children().hasClass('some-long-string')).to.equal(true);
expect(wrapper.children().hasClass('FoOo')).to.equal(true);
expect(wrapper.children().hasClass('doesnt-exist')).to.equal(false);
});
});

Expand All @@ -2209,13 +2209,13 @@ describeWithDOM('mount', () => {
expect(wrapper.hasClass('doesnt-exist')).to.equal(false);

// NOTE(lmr): the fact that this no longer works is a semantically
// meaningfull deviation in behavior
expect(wrapper.rendered().hasClass('foo')).to.equal(false);
expect(wrapper.rendered().hasClass('bar')).to.equal(false);
expect(wrapper.rendered().hasClass('baz')).to.equal(false);
expect(wrapper.rendered().hasClass('some-long-string')).to.equal(false);
expect(wrapper.rendered().hasClass('FoOo')).to.equal(false);
expect(wrapper.rendered().hasClass('doesnt-exist')).to.equal(false);
// meaningfull deviation in behavior. But this will be remedied with the ".root()" change
expect(wrapper.children().hasClass('foo')).to.equal(false);
expect(wrapper.children().hasClass('bar')).to.equal(false);
expect(wrapper.children().hasClass('baz')).to.equal(false);
expect(wrapper.children().hasClass('some-long-string')).to.equal(false);
expect(wrapper.children().hasClass('FoOo')).to.equal(false);
expect(wrapper.children().hasClass('doesnt-exist')).to.equal(false);
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/Utils-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../setupAdapters';
import './setupAdapters';
import React from 'react';
import { expect } from 'chai';

Expand All @@ -17,7 +17,7 @@ import {
mapNativeEventNames,
propFromEvent,
} from '../src/adapters/Utils';
import { REACT013 } from '../src/version';
import { REACT013 } from './version';

describe('Utils', () => {
describe('nodeEqual', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/_helpers/react-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import/prefer-default-export: 0,
*/

import { is } from '../../src/version';
import { is } from '../version';

let createClass;

Expand Down
4 changes: 2 additions & 2 deletions test/staticRender-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '../setupAdapters';
import './setupAdapters';
import React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { describeWithDOM, describeIf } from './_helpers';
import { render } from '../src/';
import { REACT013 } from '../src/version';
import { REACT013 } from './version';
import { createClass } from './_helpers/react-compat';

describeWithDOM('render', () => {
Expand Down

0 comments on commit 6966eda

Please sign in to comment.