From 7f52d376ae7241d6a19b0841a745dec570afb789 Mon Sep 17 00:00:00 2001 From: Warren Keith Date: Mon, 29 Jan 2018 09:48:23 +0000 Subject: [PATCH] Add camelCase util function Test helper nunjucks render function presumed that a file's macro would match the file name - replaced with a camelCase template name --- src/javascripts/utils.js | 11 ++++++++++- test/test-helpers.js | 4 +++- test/unit/utils.test.js | 13 +++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/javascripts/utils.js b/src/javascripts/utils.js index bc40365b7..e2e29fa39 100644 --- a/src/javascripts/utils.js +++ b/src/javascripts/utils.js @@ -49,7 +49,16 @@ export const nextUniqueId = function (i) { }; }(0); +/** + * CamelCases a dash seperated string + * @param {string} str + */ +export const camelCase = function(str: string): string { + return $.camelCase(str); +}; + export default { slugify: slugify, - nextUniqueId: nextUniqueId + nextUniqueId: nextUniqueId, + camelCase: camelCase }; diff --git a/test/test-helpers.js b/test/test-helpers.js index b36dbfb89..96b2d727e 100644 --- a/test/test-helpers.js +++ b/test/test-helpers.js @@ -10,6 +10,8 @@ const fs = require("fs"), nunjucks = require("nunjucks"), jsdom = require("jsdom"); +const { camelCase } = require("./../src/javascripts/utils"); + const { JSDOM } = jsdom; /** @@ -21,7 +23,7 @@ const { JSDOM } = jsdom; */ function renderComponent(name, data) { var template = fs.readFileSync(path.join(__dirname, `../src/components/${ name }/${ name }.njk`), "utf8"); - return nunjucks.renderString(`${ template}{{ ${ $.camelCase(name) }(content) }}"`, { content: data }); + return nunjucks.renderString(`${ template}{{ ${ camelCase(name) }(content) }}`, { content: data }); } /** diff --git a/test/unit/utils.test.js b/test/unit/utils.test.js index b31d7e1b9..b8250cb97 100644 --- a/test/unit/utils.test.js +++ b/test/unit/utils.test.js @@ -1,6 +1,6 @@ /* eslint-env node, mocha, jquery */ -import { slugify, nextUniqueId } from "../../src/javascripts/utils"; +import { slugify, nextUniqueId, camelCase } from "../../src/javascripts/utils"; describe("Utils", function() { @@ -74,14 +74,11 @@ describe("Utils", function() { }); - describe('jQuery camelCase (private method)', () => { - it('is available as a method on the jQuery object', () => { - $.camelCase.should.be.a("function"); - }); - it("turns a kebab-case string into a camelCase string", ()=>{ + describe("camelCase", function() { + it("turns a kebab-case string into a camelCase string", function() { var string = "this-is-kebab-case"; - $.camelCase(string).should.equal("thisIsKebabCase"); - }) + camelCase(string).should.equal("thisIsKebabCase"); + }); }); });