Giter VIP home page Giter VIP logo

testing-apps-with-rtl's Introduction

Testing React Applications (with React Testing Application)

This repository contains a simple React application of a Calculator and it's history can be used as a guided 'how-to' on the React testing library.

Available npm commands:

  • Run all tests: npm run test
  • Run all tests in watch mode: npm run test:watch
  • Start development environment: npm run start

Outline

This repository contains a simple application that consists in 3 different screens, where each one will support several points from the key topics to be demonstrated:

  • basics
  • elementar form testing with use of mocked functions
  • prefer userEvent over of fireEvent
  • avoid implementation details
  • mocking modules
  • useContext, render and custom render for tests
  • mocking HTTP requests

Welcome

A brief introduction to the queries provided by [React Testing Library}(https://testing-library.com/docs/react-testing-library/cheatsheet) and the extended assertions of Testing Library is covered in the welcome component. The welcome screen is also used to showcase the usage of mocked functions and a simple way to test forms.

Calculator

The calculator component is used to show how implementation details can be avoided by going throuh a refactoring that introduces the concepts of display and keyboard from this until this commit. Having a math "service" available in the calculator is the way found to represent how mocking entire modules can be done. The calculator is also the place where testing a component created with a context is showncased. The button component has been styled with a dark and light theme and the tests show how that is done.

Goodbye

The goodbye screen is used to wrap up our app. Not only it says a nice farewell to the user, but it also allows us to demostrate how to mock HTTP requests via the icanhazdadjoke api.

Finally, all three screens are connected and the app is put together on your machine. Enjoy!

For comments, questions and suggestions, feel free to contact me!

testing-apps-with-rtl's People

Contributors

ritamcastro avatar

Stargazers

Emmanuel Okuchukwu avatar Vikas avatar Brian Porter avatar FΓ‘bio Dias avatar Andre Dias avatar

Watchers

James Cloos avatar  avatar Andre Dias 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.