Skip to content

Commit 995201c

Browse files
strausrtocker
authored andcommitted
Don't render Context as div (#81)
* Add `includeOwnBody` property to Context. * Exclude src test from running on Node 6.
1 parent 24da118 commit 995201c

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ env:
1313
- TEST_SUBJECT=src
1414
- TEST_SUBJECT=lib
1515
- TEST_SUBJECT=dist
16+
matrix:
17+
exclude:
18+
- node_js: 6
19+
env: TEST_SUBJECT=src

src/components/CloudinaryContext/CloudinaryContext.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import CloudinaryComponent from '../CloudinaryComponent';
34
import { Util } from 'cloudinary-core';
45

@@ -40,7 +41,9 @@ class CloudinaryContext extends CloudinaryComponent {
4041
allowedProps[currentProp] = this.props[currentProp];
4142
return allowedProps;
4243
}, {});
43-
return <div {...nonCloudinaryProps}>{this.props.children}</div>;
44+
const {includeOwnBody, ...props} = nonCloudinaryProps;
45+
46+
return includeOwnBody ? this.props.children : <div {...props}>{this.props.children}</div>;
4447
}
4548
}
4649

@@ -53,8 +56,8 @@ CloudinaryContext.CLOUDINARY_PROPS = CloudinaryComponent.VALID_OPTIONS.reduce(
5356
{}
5457
);
5558

56-
CloudinaryContext.propTypes = CloudinaryComponent.propTypes;
57-
CloudinaryContext.defaultProps = {};
59+
CloudinaryContext.propTypes = {...CloudinaryComponent.propTypes, includeOwnBody: PropTypes.bool};
60+
CloudinaryContext.defaultProps = {includeOwnBody: false };
5861
CloudinaryContext.childContextTypes = CloudinaryComponent.contextTypes;
5962

6063
export default CloudinaryContext;

test/ContextTest.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ describe('CloudinaryContext', () => {
1919
expect(img.instance().state.url).to.equal("http://res.cloudinary.com/demo/image/upload/sample");
2020
});
2121

22+
it("should render without div", function() {
23+
let tag = mount(
24+
<CloudinaryContext className="root" cloudName="demo" includeOwnBody={true}>
25+
<Image publicId="sample" />
26+
</CloudinaryContext>
27+
);
28+
29+
expect(tag.html().startsWith("<div")).to.equal(false);
30+
});
31+
it("should render with div", function() {
32+
let tag = mount(
33+
<CloudinaryContext className="root" cloudName="demo" includeOwnBody={false}>
34+
<Image publicId="sample" />
35+
</CloudinaryContext>
36+
);
37+
38+
expect(tag.html().startsWith("<div")).to.equal(true);
39+
});
40+
2241
it("should pass properties to children with snake case", function() {
2342
let tag = mount(
2443
<CloudinaryContext className="root" cloudName="demo" fetch_format="auto" >

0 commit comments

Comments
 (0)