Files
30-seconds-of-code/test/toCamelCase.test.js
Christian C. Salvadó 83a6a6ea32 [ENHANCEMENT] Properly configure eslint to work with jest (#988)
* chore: make aware eslint that we use jest

By setting up the jest environment, we no longer need to declare the
'test' global in the configuration.

* chore: don't need to import expect, it's a jest environment global

* chore: don't need to import expect when creating undefined test
2019-06-18 08:34:45 +03:00

48 lines
1.7 KiB
JavaScript

const {toCamelCase} = require('./_30s.js');
test('toCamelCase is a Function', () => {
expect(toCamelCase).toBeInstanceOf(Function);
});
test("toCamelCase('some_database_field_name') returns someDatabaseFieldName", () => {
expect(toCamelCase('some_database_field_name')).toBe('someDatabaseFieldName');
});
test("toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized", () => {
expect(toCamelCase('Some label that needs to be camelized')).toBe(
'someLabelThatNeedsToBeCamelized'
);
});
test("toCamelCase('some-javascript-property') return someJavascriptProperty", () => {
expect(toCamelCase('some-javascript-property')).toBe('someJavascriptProperty');
});
test("toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens", () => {
expect(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens')).toBe(
'someMixedStringWithSpacesUnderscoresAndHyphens'
);
});
test('toCamelCase() throws a error', () => {
expect(() => {
toCamelCase();
}).toThrow();
});
test('toCamelCase([]) throws a error', () => {
expect(() => {
toCamelCase([]);
}).toThrow();
});
test('toCamelCase({}) throws a error', () => {
expect(() => {
toCamelCase({});
}).toThrow();
});
test('toCamelCase(123) throws a error', () => {
expect(() => {
toCamelCase(123);
}).toThrow();
});
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();
});