Skip to content

Latest commit

 

History

History
148 lines (91 loc) · 2.39 KB

10-testing.md

File metadata and controls

148 lines (91 loc) · 2.39 KB

10 - Testing

The repository includes pre-written tests to verify your application works correctly. If all tests pass, your app is built properly!


Step 1: Run the Tests

  1. Open your terminal in the project directory

  2. Run the test command:

npm test
  1. Wait for the tests to complete

Step 2: Check the Results

If All Tests Pass

You should see output like this:

 PASS  tests/pokemonService.test.js
 PASS  tests/api.test.js

Test Suites: 2 passed, 2 total
Tests:       25 passed, 25 total

All tests passing means your app is built correctly!


If Tests Fail

You'll see output showing which tests failed:

 FAIL  tests/api.test.js
  ● Pokemon API Endpoints › GET /api/pokemon › should return pokemon list

    Expected: 200
    Received: 500

This means something is wrong with your code. Check:

  1. File names - Are all files named correctly?
  2. File locations - Are files in the correct folders?
  3. Exports - Did you export all functions?
  4. Typos - Check for spelling mistakes in your code

Step 3: Fix Failing Tests

  1. Read the error message to find which test failed

  2. The test name tells you what's broken:

    • GET /api/pokemon → Check your routes and controllers
    • getPokemonDetails → Check your service layer
    • Failed to fetch → Check your repository layer
  3. Fix the issue in your code

  4. Run tests again:

npm test
  1. Repeat until all tests pass

Step 4: Run Code Quality Checks

  1. Check for linting errors:
npm run lint
  1. If there are errors, fix them automatically:
npm run lint:fix
  1. Check code formatting:
npm run format:check
  1. If formatting is wrong, fix it:
npm run format

Step 5: Verify Everything Passes

  1. Run all checks together:
npm run lint && npm run format:check && npm test
  1. All commands should complete without errors

  2. If everything passes, your app is ready!


Step 6: Commit Your Progress

  1. Stage your changes:
git add .
  1. Commit with the conventional format:
git commit -m "test: verify all tests pass

Full Name: Juan Dela Cruz
Umindanao: juan.delacruz@email.com"
  1. Replace the name and email with your own information

What's Next?

Let's put it all together and run the application!

Next: 11 - Running the App