Theme
Primary Color
Lesson 17

Code Coverage

input.js
/*
  filterName Function
  [1] If No Name Is Given It Will Show "Unknown"
  [2] If Name Starts Or Ends With Space It Will Be Trimmed
  [3] If Name Length > 10 It Will Show Only First 10 Characters
  [4] If Name Starts With Underscore It Will Not Show The Underscore
*/

function filterName(name) {
  if (name === undefined) {
    name = "Unknown";
  }
  if (name.startsWith(" ") || name.endsWith(" ")) {
    name = name.trim();
  }
  if (name.length > 10) {
    name = name.substring(0, 10);
  }
  if (name.startsWith("_")) {
    name = name.substring(1);
  }
  if (name === "Hell") {
    throw Error("This Name Is Not Allowed");
  }
  return name;
}

module.exports = filterName;
package.json
{
  "name": "jest_testing",
  "version": "1.0.0",
  "description": "For Unit Testing Course",
  "main": "index.js",
  "scripts": {
    "test": "jest --watchAll"
  },
  "author": "Elzero",
  "license": "ISC",
  "devDependencies": {
    "jest": "^26.0.1"
  },
  "jest": {
    "collectCoverage": true,
    "coverageReporters": [
      "html"
    ]
  }
}