Skip to content

Instantly share code, notes, and snippets.

@RanjanSushant
Created January 29, 2022 07:54
Show Gist options
  • Save RanjanSushant/4c013471b48aedff03bbaefb018836b5 to your computer and use it in GitHub Desktop.
Save RanjanSushant/4c013471b48aedff03bbaefb018836b5 to your computer and use it in GitHub Desktop.
Codesphere Jest demo javascript file and testing file
//case sensitive palindrome check for strings
function isPalindrome(str) {
const reversedString = reverseStr(str);
return reversedString === str;
}
//function to reverse string
function reverseStr(str) {
str = str.split("").reverse().join("");
return str;
}
//exporting the functions to be tested
module.exports = { isPalindrome, reverseStr };
const { isPalindrome, reverseStr } = require("./demo");
//checking if functiona are defined
test("Functions are defined", () => {
expect(reverseStr).toBeDefined();
expect(isPalindrome).toBeDefined();
});
//Checking reverseStr works properly
test("String reverses", () => {
expect(reverseStr("Hello World")).toBe("dlroW olleH");
});
//Checking positive testcase for isPalindrome function
test("Palindorme returns true", () => {
expect(isPalindrome("racecar")).toBeTruthy();
});
//Checking negative testcase for isPalindrome function
test("Palindorme returns false", () => {
expect(isPalindrome("palindrome")).toBeFalsy();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment