Created
January 29, 2022 07:54
-
-
Save RanjanSushant/4c013471b48aedff03bbaefb018836b5 to your computer and use it in GitHub Desktop.
Codesphere Jest demo javascript file and testing file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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