Giter VIP home page Giter VIP logo

hook-testing's Introduction

React + Vite

Before Getting Started

The goal of this project is to practice testing hooks since they work a bit different than components. The code for this project is identical to the code for our useLocalStorage custom hook project.

Instructions

  1. Testing the following features of the useLocalStorage hook:
    • Ensure the initial value passed to the useLocalStorage hook is stored in localStorage. This should also work with passing a function to useLocalStorage as well.
    • Ensure localStorage is updated whenever setValue is called.
    • Ensure localStorage is cleared whenever setValue is called with undefined.
    • Ensure useLocalStorage uses the value from localStorage if it exists instead of the initial value passed to useLocalStorage.

Gotcha

  1. TypeError: Cannot convert undefined or null to object in expect.extend(matchers) setUpTests.js

    • make sure in package.json if you have creatd new Vit + react project or use the project package.json
      "devDependencies": {
          "@testing-library/jest-dom": "^5.16.5", **is this version
          "@testing-library/react": "^14.0.0",
          "@testing-library/user-event": "^14.4.3",
          "@types/react": "^18.0.27",
          "@types/react-dom": "^18.0.10",
          "@vitejs/plugin-react-swc": "^3.0.0",
          "jsdom": "^22.1.0",
          "vite": "^4.1.0",
          "vitest": "^0.32.2" **is this version
      }

Running Tests

To run tests, run the following command

  npm run test

Installation

Install my-project with npm

  cd my-project
  npm install

hook-testing's People

Contributors

codecamp-prem avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.