Skip to content

Commit

Permalink
Added tests for _truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
allenjiji committed Dec 8, 2023
1 parent 823bc0a commit 8f8c30b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const _humanize = /*#__PURE__*/ nullSafe(humanize);
export const _snakeToCamelCase = /*#__PURE__*/ nullSafe(snakeToCamelCase);
export const _camelToSnakeCase = /*#__PURE__*/ nullSafe(camelToSnakeCase);
export const _capitalize = /*#__PURE__*/ nullSafe(capitalize);
export const _hyphenate = /*#__PURE__*/ nullSafe(hyphenate);
// eslint-disable-next-line @bigbinary/neeto/use-camel-case-or-pascal-case-for-function-names
export const _hyphenate = (string, length) =>
isNil(string) ? string : hyphenate(string, length);
// eslint-disable-next-line @bigbinary/neeto/use-camel-case-or-pascal-case-for-function-names
export const _truncate = (string, length) =>
isNil(string) ? string : truncate(string, length);
13 changes: 13 additions & 0 deletions tests/string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
slugify,
capitalize,
hyphenate,
_hyphenate,
truncate,
_truncate,
} from "src/strings";

describe("String operations", () => {
Expand Down Expand Up @@ -48,8 +50,19 @@ describe("String operations", () => {
expect(hyphenate("helloWorld")).toBe("hello-world");
});

test("_hyphenate() method should hyphenate the string", () => {
expect(_hyphenate("Hello World")).toBe("hello-world");
expect(_hyphenate("hello_world")).toBe("hello-world");
expect(_hyphenate("helloWorld")).toBe("hello-world");
});

test("truncate() method should truncate the string if it is longer than specified string length", () => {
expect(truncate("Hello World", 5)).toBe("Hello...");
expect(truncate("Hello World", 15)).toBe("Hello World");
});

test("_truncate() method should truncate the string if it is longer than specified string length", () => {
expect(_truncate("Hello World", 5)).toBe("Hello...");
expect(_truncate("Hello World", 15)).toBe("Hello World");
});
});

0 comments on commit 8f8c30b

Please sign in to comment.