Giter VIP home page Giter VIP logo

adam-marianowski / react-todos-app Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 4.69 MB

Simple TODOs App built with React and Typescript (Vite, Json Placeholder API and Canva for logo). Deployed on Netlify. Unit Testing with Vitest, React Testing Library and MSW

Home Page: https://adam-marianowski-react-todos-app.netlify.app/

JavaScript 3.86% HTML 3.24% CSS 29.06% TypeScript 63.85%
canvas json-placeholder mswjs react react-typescript reactjs testing-library-react todo todoapp todolist todos typescript vite vite-react-typescript vitejs vitest

react-todos-app's Introduction

React Todos App

screenshot

  • Simple React application for managing TODOs.
  • App written without any additional 3rd parties libraries.
  • Very simple app demonstrating the basics of React.
  • App is performing API requests to JSON placeholder API.
  • This Application is built with Vite.
  • Unit Testing with Vitest, React-Testing-Library and MSW

Technologies

  • React
  • TypeScript
  • Canva (for logo)
  • Json placeholder API
  • Vite
  • Vitest
  • React-testin-library
  • MSW

Features

  • Add new TODO
  • Mark TODO as completed
  • Delete TODO

Installation

  1. Clone the repository
  2. Run npm install
  3. Run npm run dev

Demo

You can watch demo here

Application is deployed on Netlify. You can see it here

react-todos-app's People

Contributors

adam-marianowski avatar

Stargazers

 avatar

react-todos-app's Issues

Unit testing - new calls to server are breaking addTodo function

Whenever I'm adding new unit test which needs to be handled by MSW server it breaks the addTodo test. It seems that there is problem with MSW server configuration.

TypeError: Failed to fetch
 createNetworkError react-todos-app/node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.mjs:157:24
 globalThis.fetch .../index.mjs:98:31
 runNextTicks node:internal/process/task_queues:60:5
  listOnTimeout node:internal/timers:540:9
  processTimers node:internal/timers:514:7
// this breaks whenever deleteTodo test is declared
  it('should add a new todo', async () => {
    const { result } = renderHook(() => useTodos());
    await waitFor(() => result.current.todos.length > 0);

    result.current.addTodo('new todo');
    await waitFor(() => result.current.todos.length > 2);

    expect(result.current.todos[0].title).toBe('new todo');
  });

  it('should delete a todo', async () => {
// this breaks addtodo test.
    const { result } = renderHook(() => useTodos());
    await waitFor(() => result.current.todos.length > 0);

    result.current.deleteTodo(1);

    await waitFor(() => result.current.todos.length < 2);
    expect(result.current.todos.length).toBe(1);
  });

MSW server setup:

const initialTodos = [
  { id: 1, title: 'todo 1', completed: true },
  { id: 2, title: 'todo 2', completed: false },
];
const newTodo = { id: 3, title: 'new todo', completed: false };

describe('useTodos', () => {
  const server = setupServer(
    http.get('https://jsonplaceholder.typicode.com/todos', () => {
      return HttpResponse.json(initialTodos);
    }),
    http.post('https://jsonplaceholder.typicode.com/todos', () => {
      return HttpResponse.json(newTodo);
    }),
    http.delete('https://jsonplaceholder.typicode.com/todos/:id', (req, res, ctx) => {
      return res(ctx.status(200));
    })
  );

  beforeAll(() => server.listen());
  afterEach(() => server.resetHandlers());
  afterAll(() => server.close());

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.