Skip to content

Commit

Permalink
Failing tests for #1683
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 2, 2018
1 parent 6cd6fa2 commit 0c8ec0e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from './_helpers';
import { REACT013, REACT014, REACT16, REACT163, is } from './_helpers/version';
import realArrowFunction from './_helpers/realArrowFunction';
import sloppyReturnThis from './_helpers/untranspiledSloppyReturnThis';

const getElementPropSelector = prop => x => x.props[prop];
const getWrapperPropSelector = prop => x => x.prop(prop);
Expand Down Expand Up @@ -2057,6 +2058,51 @@ describeWithDOM('mount', () => {

expect(wrapper.props()).to.eql({ bar: 'bye', foo: 'hi' });
});

const SloppyReceiver = sloppyReturnThis((
receiver,
props = { NO_PROPS: true },
context,
) => {
return (
<div
data-is-global={receiver === global}
data-is-undefined={typeof receiver === 'undefined'}
{...props}
{...context}
/>
);
});

const StrictReceiver = function SFC(
props = { NO_PROPS: true },
context,
) {
return (
<div
data-is-global={this === global}
data-is-undefined={typeof this === 'undefined'}
{...props}
{...context}
/>
);
};

it('does not provide a `this` to a sloppy-mode SFC', () => {
const wrapper = mount(<SloppyReceiver />);
expect(wrapper.childAt(0).props()).to.be.an('object').that.has.all.keys({
'data-is-global': true,
'data-is-undefined': false,
});
});

it('does not provide a `this` to a strict-mode SFC', () => {
const wrapper = mount(<StrictReceiver />);
expect(wrapper.childAt(0).props()).to.be.an('object').that.has.all.keys({
'data-is-global': false,
'data-is-undefined': true,
});
});
});
});

Expand Down
46 changes: 46 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './_helpers/setupAdapters';
import { createClass, createContext } from './_helpers/react-compat';
import { describeIf, itIf, itWithData, generateEmptyRenderData } from './_helpers';
import { REACT013, REACT014, REACT15, REACT150_4, REACT16, REACT163, is } from './_helpers/version';
import sloppyReturnThis from './_helpers/untranspiledSloppyReturnThis';

// The shallow renderer in react 16 does not yet support batched updates. When it does,
// we should be able to go un-skip all of the tests that are skipped with this flag.
Expand Down Expand Up @@ -1826,6 +1827,51 @@ describe('shallow', () => {

expect(wrapper.props()).to.eql({ className: 'bye', id: 'hi' });
});

const SloppyReceiver = sloppyReturnThis((
receiver,
props = { NO_PROPS: true },
context,
) => {
return (
<div
data-is-global={receiver === global}
data-is-undefined={typeof receiver === 'undefined'}
{...props}
{...context}
/>
);
});

const StrictReceiver = function SFC(
props = { NO_PROPS: true },
context,
) {
return (
<div
data-is-global={this === global}
data-is-undefined={typeof this === 'undefined'}
{...props}
{...context}
/>
);
};

it('does not provide a `this` to a sloppy-mode SFC', () => {
const wrapper = shallow(<SloppyReceiver />);
expect(wrapper.props()).to.be.an('object').that.has.all.keys({
'data-is-global': true,
'data-is-undefined': false,
});
});

it('does not provide a `this` to a strict-mode SFC', () => {
const wrapper = shallow(<StrictReceiver />);
expect(wrapper.props()).to.be.an('object').that.has.all.keys({
'data-is-global': false,
'data-is-undefined': true,
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function (fn) {
return function () {
return fn.apply(null, [this].concat(Array.prototype.slice.call(arguments)));
};
};

0 comments on commit 0c8ec0e

Please sign in to comment.