Skip to content

Commit

Permalink
Add camelCase util function
Browse files Browse the repository at this point in the history
Test helper nunjucks render function presumed that a file's macro would match the file name - replaced with a camelCase template name
  • Loading branch information
Warren Keith committed Jan 29, 2018
1 parent b81b03d commit 7f52d37
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/javascripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
4 changes: 3 additions & 1 deletion test/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const fs = require("fs"),
nunjucks = require("nunjucks"),
jsdom = require("jsdom");

const { camelCase } = require("./../src/javascripts/utils");

const { JSDOM } = jsdom;

/**
Expand All @@ -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 });
}

/**
Expand Down
13 changes: 5 additions & 8 deletions test/unit/utils.test.js
Original file line number Diff line number Diff line change
@@ -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() {

Expand Down Expand Up @@ -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");
});
});

});

0 comments on commit 7f52d37

Please sign in to comment.