Quality Assurance Projects - Metric-Imperial Converter

Hi my tests are not passing, none, but in the application they are
What can it be?

Your project link(s)

solution: https://suemetricimperialconvert.herokuapp.com
repository: GitHub - DiogoJorge1401/MetricImperialConverter

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36

Challenge: Quality Assurance Projects - Metric-Imperial Converter

Link to the challenge:
https ://www.freecodecamp.org/learn/quality-assurance/quality-assurance-projects/metric-imperial-converter

To run the project you can install the dependencies with npm or yarn, and to run it in production mode just run the build command and then the start command, in the case of development mode just run the dev command.

I ended up changing the test-runner file because it appears in the browser console that the run method was being called, but it didn’t exist, so I just chose to create another object with Object.assign adding the method in this way

oh i see
This error was generated because I didn’t create a variable for the application’s port value, I ended up duplicating code and forgetting to use the ||
I will correct and upload the commit

In relation to the message Running Tests.... it appears because the application is running with the environment variable NODE_ENV with the value β€œtest”

actually i’m thinking of migrating this project to javascript vanila, maybe it will solve the problems

The following is what I would expect to see when the app runs:

Listening on port 3000
Running Tests...


  Unit Tests
    Function convertHandler.getNum(input)
      βœ” Whole number input
      βœ” Decimal Input
      βœ” Fractional Input
      βœ” Fractional Input w/ Decimal
      βœ” Invalid Input (double fraction)
      βœ” No Numerical Input
    Function convertHandler.getUnit(input)
      βœ” For Each Valid Unit Inputs
      βœ” Unknown Unit Input
    Function convertHandler.getReturnUnit(initUnit)
      βœ” For Each Valid Unit Inputs
    Function convertHandler.spellOutUnit(unit)
      βœ” For Each Valid Unit Inputs
    Function convertHandler.convert(num, unit)
      βœ” Gal to L
      βœ” L to Gal
      βœ” Mi to Km
      βœ” Km to Mi
      βœ” Lbs to Kg
      βœ” Kg to Lbs

  Functional Tests
    Routing Tests
      GET /api/convert => conversion object
        βœ” Convert 10L (valid input)
        βœ” Convert 32g (invalid input unit)
        βœ” Convert 3/7.2/4kg (invalid number)
        βœ” Convert 3/7.2/4kilomegagram (invalid number and unit)
        βœ” Convert kg (no number)


  21 passing (56ms)

You should have not messed with test-runner.js or fcc-testing because you have tweaked something that is causing no tests to be sent back to freeCodeCamp.

A call to https://suemetricimperialconvert.herokuapp.com/_api/get-tests should send back a response like:

[
  {
    "title": "Whole number input",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "32"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1060934"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "123"
        ]
      }
    ]
  },
  {
    "title": "Decimal Input",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "4.3"
        ]
      }
    ]
  },
  {
    "title": "Fractional Input",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "3/4"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getNum(input)",
          "\"Divide by zero should return null\""
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1/3"
        ]
      }
    ]
  },
  {
    "title": "Fractional Input w/ Decimal",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "0.5"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "9"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "8/1.4"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getNum(input)",
          "\"Divide by zero should return null\""
        ]
      }
    ]
  },
  {
    "title": "Invalid Input (double fraction)",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "isNull",
        "args": [
          "convertHandler.getNum(input)",
          "\"Double fractions should return null\""
        ]
      }
    ]
  },
  {
    "title": "No Numerical Input",
    "context": " -> Unit Tests -> Function convertHandler.getNum(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "convertHandler.getNum(input)",
          "1"
        ]
      }
    ]
  },
  {
    "title": "For Each Valid Unit Inputs",
    "context": " -> Unit Tests -> Function convertHandler.getUnit(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getUnit(1 + ele)",
          "output[index]"
        ]
      }
    ]
  },
  {
    "title": "Unknown Unit Input",
    "context": " -> Unit Tests -> Function convertHandler.getUnit(input)",
    "state": "passed",
    "assertions": [
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123kgm')"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123kmg')"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123lkg')"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123lb')"
        ]
      },
      {
        "method": "isNull",
        "args": [
          "convertHandler.getUnit('123k')"
        ]
      }
    ]
  },
  {
    "title": "For Each Valid Unit Inputs",
    "context": " -> Unit Tests -> Function convertHandler.getReturnUnit(initUnit)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.getReturnUnit(ele)",
          "expect[i]"
        ]
      }
    ]
  },
  {
    "title": "For Each Valid Unit Inputs",
    "context": " -> Unit Tests -> Function convertHandler.spellOutUnit(unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "convertHandler.spellOutUnit(ele)",
          "expect[i]"
        ]
      }
    ]
  },
  {
    "title": "Gal to L",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "L to Gal",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Mi to Km",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Km to Mi",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Lbs to Kg",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Kg to Lbs",
    "context": " -> Unit Tests -> Function convertHandler.convert(num, unit)",
    "state": "passed",
    "assertions": [
      {
        "method": "approximately",
        "args": [
          "convertHandler.convert(input[0],input[1])",
          "expected",
          "0.1"
        ]
      }
    ]
  },
  {
    "title": "Convert 10L (valid input)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.initNum",
          "10"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.initUnit",
          "'L'"
        ]
      },
      {
        "method": "approximately",
        "args": [
          "res.body.returnNum",
          "2.64172",
          "0.1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.returnUnit",
          "'gal'"
        ]
      }
    ]
  },
  {
    "title": "Convert 32g (invalid input unit)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.text",
          "\"invalid unit\""
        ]
      }
    ]
  },
  {
    "title": "Convert 3/7.2/4kg (invalid number)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.text",
          "\"invalid number\""
        ]
      }
    ]
  },
  {
    "title": "Convert 3/7.2/4kilomegagram (invalid number and unit)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.text",
          "\"invalid number and unit\""
        ]
      }
    ]
  },
  {
    "title": "Convert kg (no number)",
    "context": " -> Functional Tests -> Routing Tests -> GET /api/convert => conversion object",
    "state": "passed",
    "assertions": [
      {
        "method": "equal",
        "args": [
          "res.status",
          "200"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.initNum",
          "1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.initUnit",
          "'kg'"
        ]
      },
      {
        "method": "approximately",
        "args": [
          "res.body.returnNum",
          "2.20462",
          "0.1"
        ]
      },
      {
        "method": "equal",
        "args": [
          "res.body.returnUnit",
          "'lbs'"
        ]
      }
    ]
  }
]

Instead, the response is [ ]

1 Like

Ok now I understand where the error is, I will refactor the project to just javascript, thanks a lot for the help

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.