diff --git a/src/components/CloudinaryContext/CloudinaryContext.js b/src/components/CloudinaryContext/CloudinaryContext.js index 413d4e5..683d5d2 100644 --- a/src/components/CloudinaryContext/CloudinaryContext.js +++ b/src/components/CloudinaryContext/CloudinaryContext.js @@ -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. @@ -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; } diff --git a/test/ContextTest.js b/test/ContextTest.js index b4fe7d5..6e7c755 100644 --- a/test/ContextTest.js +++ b/test/ContextTest.js @@ -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( + + + + ); + + 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( + + + + ); + + 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(