diff --git a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx index 535f0f02c..d882abe7b 100644 --- a/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx @@ -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); @@ -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 ( +
+ ); + }); + + const StrictReceiver = function SFC( + props = { NO_PROPS: true }, + context, + ) { + return ( +
+ ); + }; + + it('does not provide a `this` to a sloppy-mode SFC', () => { + const wrapper = mount(); + 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(); + expect(wrapper.childAt(0).props()).to.be.an('object').that.has.all.keys({ + 'data-is-global': false, + 'data-is-undefined': true, + }); + }); }); }); diff --git a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx index 7d6c31065..0e55067aa 100644 --- a/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx +++ b/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx @@ -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. @@ -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 ( +
+ ); + }); + + const StrictReceiver = function SFC( + props = { NO_PROPS: true }, + context, + ) { + return ( +
+ ); + }; + + it('does not provide a `this` to a sloppy-mode SFC', () => { + const wrapper = shallow(); + 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(); + expect(wrapper.props()).to.be.an('object').that.has.all.keys({ + 'data-is-global': false, + 'data-is-undefined': true, + }); + }); }); }); diff --git a/packages/enzyme-test-suite/test/_helpers/untranspiledSloppyReturnThis.js b/packages/enzyme-test-suite/test/_helpers/untranspiledSloppyReturnThis.js new file mode 100644 index 000000000..b97d7beb6 --- /dev/null +++ b/packages/enzyme-test-suite/test/_helpers/untranspiledSloppyReturnThis.js @@ -0,0 +1,5 @@ +module.exports = function (fn) { + return function () { + return fn.apply(null, [this].concat(Array.prototype.slice.call(arguments))); + }; +};