Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
10
test/toCamelCase/toCamelCase.js
Normal file
10
test/toCamelCase/toCamelCase.js
Normal file
@ -0,0 +1,10 @@
|
||||
const toCamelCase = str => {
|
||||
let s =
|
||||
str &&
|
||||
str
|
||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||
.map(x => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
|
||||
.join('');
|
||||
return s.slice(0, 1).toLowerCase() + s.slice(1);
|
||||
};
|
||||
module.exports = toCamelCase;
|
||||
24
test/toCamelCase/toCamelCase.test.js
Normal file
24
test/toCamelCase/toCamelCase.test.js
Normal file
@ -0,0 +1,24 @@
|
||||
const expect = require('expect');
|
||||
const toCamelCase = require('./toCamelCase.js');
|
||||
|
||||
|
||||
test('toCamelCase is a Function', () => {
|
||||
expect(toCamelCase).toBeInstanceOf(Function);
|
||||
});
|
||||
t.equal(toCamelCase('some_database_field_name'), 'someDatabaseFieldName', "toCamelCase('some_database_field_name') returns someDatabaseFieldName");
|
||||
t.equal(toCamelCase('Some label that needs to be camelized'), 'someLabelThatNeedsToBeCamelized', "toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized");
|
||||
t.equal(toCamelCase('some-javascript-property'), 'someJavascriptProperty', "toCamelCase('some-javascript-property') return someJavascriptProperty");
|
||||
t.equal(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'), 'someMixedStringWithSpacesUnderscoresAndHyphens', "toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens");
|
||||
t.throws(() => toCamelCase(), 'toCamelCase() throws a error');
|
||||
t.throws(() => toCamelCase([]), 'toCamelCase([]) throws a error');
|
||||
t.throws(() => toCamelCase({}), 'toCamelCase({}) throws a error');
|
||||
t.throws(() => toCamelCase(123), 'toCamelCase(123) throws a error');
|
||||
|
||||
let start = new Date().getTime();
|
||||
toCamelCase('some-mixed_string with spaces_underscores-and-hyphens');
|
||||
let end = new Date().getTime();
|
||||
test('toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user