Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/CloudinaryContext/CloudinaryContext.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import CloudinaryComponent from '../CloudinaryComponent';
import { Util } from 'cloudinary-core';

/**
* Provides a container for Cloudinary components. Any option set in CloudinaryContext will be passed to the children.
Expand All @@ -19,9 +20,11 @@ class CloudinaryContext extends CloudinaryComponent {

getChildContext() {
let context = {};
const camelProps = Util.withCamelCaseKeys(this.props);

// only pass valid Cloudinary options
CloudinaryComponent.VALID_OPTIONS.forEach(key => {
let val = this.props[key] || this.context[key];
let val = camelProps[key] || this.context[key];
if (val !== undefined && val !== null) {
context[key] = val;
}
Expand Down
22 changes: 22 additions & 0 deletions test/ContextTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ describe('CloudinaryContext', () => {
expect(img.instance().state.url).to.equal("http://res.cloudinary.com/demo/image/upload/sample");
});

it("should pass properties to children with snake case", function() {
let tag = mount(
<CloudinaryContext className="root" cloudName="demo" fetch_format="auto" >
<Image publicId="sample" />
</CloudinaryContext>
);

let img = tag.find("div").childAt(0);
expect(img.instance().state.url).to.equal("http://res.cloudinary.com/demo/image/upload/f_auto/sample");
});

it("should pass properties to children with kebab case", function() {
let tag = mount(
<CloudinaryContext className="root" cloudName="demo" fetch-format="auto" >
<Image publicId="sample" />
</CloudinaryContext>
);

let img = tag.find("div").childAt(0);
expect(img.instance().state.url).to.equal("http://res.cloudinary.com/demo/image/upload/f_auto/sample");
});

it("should remove Cloudinary custom properties from CloudinaryContext component", function() {
let html = mount(
<CloudinaryContext
Expand Down