diff --git a/test/longestItem.test.js b/test/longestItem.test.js index b0a6fc999..03feb27ce 100644 --- a/test/longestItem.test.js +++ b/test/longestItem.test.js @@ -19,8 +19,10 @@ test('Returns the longest array', () => { test('Returns the longest object when comparing arrays and strings', () => { expect(longestItem([1, 2, 3], 'foobar')).toEqual('foobar'); }); -test('Returns undefined without any input', () => { - expect(longestItem()).toEqual(undefined); +test('Returns TypeError without any input', () => { + expect(() => { + longestItem(); + }).toThrow(TypeError); }); test('Returns first found of all similar', () => { expect(longestItem('a', 'b', 'c')).toEqual('a'); diff --git a/test/toTitleCase.test.js b/test/toTitleCase.test.js new file mode 100644 index 000000000..cc46ad6d8 --- /dev/null +++ b/test/toTitleCase.test.js @@ -0,0 +1,48 @@ +const expect = require('expect'); +const {toTitleCase} = require('./_30s.js'); + +test('toTitleCase is a Function', () => { + expect(toTitleCase).toBeInstanceOf(Function); +}); +test("toTitleCase('some_database_field_name') returns Some Database Field Name", () => { + expect(toTitleCase('some_database_field_name')).toBe('Some Database Field Name'); +}); +test("toTitleCase('Some label that needs to be titled') returns Some Label That Needs To Be Titled", () => { + expect(toTitleCase('Some label that needs to be titled')).toBe( + 'Some Label That Needs To Be Titled' + ); +}); +test("toTitleCase('some-javaScript-property') return Some Java Script Property", () => { + expect(toTitleCase('some-javaScript-property')).toBe('Some Java Script Property'); +}); +test("toTitleCase('some-mixed_string with spaces_underscores-and-hyphens') returns Some Mixed String With Spaces Underscores And Hyphens", () => { + expect(toTitleCase('some-mixed_string with spaces_underscores-and-hyphens')).toBe( + 'Some Mixed String With Spaces Underscores And Hyphens' + ); +}); +test('toTitleCase() throws a error', () => { + expect(() => { + toTitleCase(); + }).toThrow(); +}); +test('toTitleCase([]) throws a error', () => { + expect(() => { + toCamelCase([]); + }).toThrow(); +}); +test('toCamelCase({}) throws a error', () => { + expect(() => { + toTitleCase({}); + }).toThrow(); +}); +test('toTitleCase(123) throws a error', () => { + expect(() => { + toTitleCase(123); + }).toThrow(); +}); +let start = new Date().getTime(); +toTitleCase('some-mixed_string with spaces_underscores-and-hyphens'); +let end = new Date().getTime(); +test('toTitleCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run', () => { + expect(end - start < 2000).toBeTruthy(); +});