I am very new to mocha and got stuck with testing below functionality. I have following string replace_underscore_with_hyphen
. I am replacing this with replace-underscore-with-hyphen
using below functionality.
const type = "replace_underscore_with_hyphen";
type = type.replace(/_/ig, '-');
But please may I know how do I test this functionality in mocha.
You can test that final string contains hyphen, and doesn't underscores:
const replaceUnderscores = () => {
const type = "replace_underscore_with_hyphen";
return type.replace(/_/ig, '-');
}
it('should replace underscores with hyphen', () => {
const replaced = replaceUnderscores();
expect(replaced).not.toContain('_');
expect(replaced).toContain('-');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.