Added test file and return types to functions

parent 681e728a
......@@ -4,17 +4,17 @@
* @Copyright (c) 2018, Marcel Dominic Bandowski.
* Released under the MIT License.
*/
import camelCase from "camelcase";
const camelcase = require("camelcase");
import fileExtension from "file-extension";
const fileExtension = require("file-extension");
/**
* compare the input before and after the conversion
* @param input
* @returns {boolean}
*/
export const checkString = (input: string) => {
return input === camelCase(input);
export const checkString = (input: string): boolean => {
return input === camelcase(input);
};
/**
......@@ -22,7 +22,11 @@ export const checkString = (input: string) => {
* @param input
* @returns {boolean}
*/
export const checkFile = (input: string) => {
const fileName = input.replace(`.${fileExtension(input, {preserveCase: true})}`, "");
return fileName === camelCase(fileName);
export const checkFile = (input: string): boolean => {
if (input.match(new RegExp(/^.*\./))) {
const fileName = input.replace(`.${fileExtension(input, {preserveCase: true})}`, "");
return fileName === camelcase(fileName);
} else {
return false;
}
};
\ No newline at end of file
import {checkFile, checkString} from "../index";
/**
* @section checkString tests
*/
/**
* Test with correct input
*/
test('checkStringCorrect', () => {
expect(checkString("camelCase")).toBe(true);
});
/**
* Test with wrong input because of first char uppercase
*/
test('checkStringWrong', () => {
expect(checkString("CamelCase")).toBe(false);
expect(checkString("Camel Case")).toBe(false);
});
/**
* @section checkFile tests
*/
/**
* Test with correct jpg file format input
*/
test('checkFileCorrectJPG', () => {
expect(checkFile("camelCase.jpg")).toBe(true);
expect(checkFile("camelCase.JPG")).toBe(true);
});
/**
* Test with wrong jpg file format input
*/
test('checkFileWrongJPG', () => {
expect(checkFile("CamelCase.jpg")).toBe(false);
expect(checkFile("CamelCase.JPG")).toBe(false);
expect(checkFile("Camel Case.jpg")).toBe(false);
expect(checkFile("Camel Case.JPG")).toBe(false);
});
/**
* Test with missing file extension
*/
test('checkFileMissingFileExtension', () => {
expect(checkFile("camelCase")).toBe(false);
expect(checkFile("CamelCase")).toBe(false);
expect(checkFile("camel Case")).toBe(false);
expect(checkFile("Camel Case")).toBe(false);
});
\ No newline at end of file
export function camelcase(input: string, options?: Object): string;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment