All Projects → kentcdodds → Dom Testing Library With Anything

kentcdodds / Dom Testing Library With Anything

Licence: other
Use DOM Testing Library to test any JS framework on TestingJavaScript.com

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Dom Testing Library With Anything

Beginners Guide To React
The Beginner's Guide To ReactJS
Stars: ✭ 354 (+100%)
Mutual labels:  kcd-edu
Advanced React Hooks
Learn Advanced React Hooks workshop
Stars: ✭ 1,208 (+582.49%)
Mutual labels:  kcd-edu
Advanced React Patterns
This is the latest advanced react patterns workshop
Stars: ✭ 1,899 (+972.88%)
Mutual labels:  kcd-edu
Testing React Apps
A workshop for testing react applications
Stars: ✭ 443 (+150.28%)
Mutual labels:  kcd-edu
Advanced React Patterns V1
The course material for my advanced react patterns course on Egghead.io
Stars: ✭ 1,106 (+524.86%)
Mutual labels:  kcd-edu
Simply React
Stars: ✭ 101 (-42.94%)
Mutual labels:  kcd-edu
Jest Cypress React Babel Webpack
Configure Jest for Testing JavaScript Applications and Install, Configure, and Script Cypress for JavaScript Web Applications on TestingJavaScript.com
Stars: ✭ 339 (+91.53%)
Mutual labels:  kcd-edu
Static Testing Tools
Static Analysis Testing JavaScript Applications on TestingJavaScript.com
Stars: ✭ 141 (-20.34%)
Mutual labels:  kcd-edu
10 Practical Js Features
Stars: ✭ 68 (-61.58%)
Mutual labels:  kcd-edu
Advanced React Patterns V2
Created with CodeSandbox
Stars: ✭ 1,495 (+744.63%)
Mutual labels:  kcd-edu
React Suspense
React Suspense workshop
Stars: ✭ 491 (+177.4%)
Mutual labels:  kcd-edu
React Performance
Let's make our apps fast ⚡
Stars: ✭ 1,035 (+484.75%)
Mutual labels:  kcd-edu
App Dev Tools
An example of how to create and hook up App DevTools to improve your development productivity of your application
Stars: ✭ 102 (-42.37%)
Mutual labels:  kcd-edu
Stack Overflow Copy Paste
Utility functions copy/pasted (and modified slightly) from Stack Overflow
Stars: ✭ 399 (+125.42%)
Mutual labels:  kcd-edu
Modern Javascript
Get up to speed on the latest, most useful JavaScript features to level up your programming
Stars: ✭ 123 (-30.51%)
Mutual labels:  kcd-edu
Es6 Todomvc
The vanillajs example converted to es6
Stars: ✭ 351 (+98.31%)
Mutual labels:  kcd-edu
Testing Workshop
A workshop for learning how to test JavaScript applications
Stars: ✭ 1,276 (+620.9%)
Mutual labels:  kcd-edu
Bookshelf
Build a ReactJS App workshop
Stars: ✭ 2,179 (+1131.07%)
Mutual labels:  kcd-edu
React Hooks And Suspense Egghead Playlist
This is the code for the egghead playlist "React Hooks and Suspense"
Stars: ✭ 128 (-27.68%)
Mutual labels:  kcd-edu
React Hooks
Learn React Hooks! 🎣 ⚛
Stars: ✭ 1,988 (+1023.16%)
Mutual labels:  kcd-edu

Use DOM Testing Library to test any JS framework


Anything you can render to the DOM, you can test with DOM Testing Library.

This repo is a bunch of simple examples of using DOM Testing Library to test a Counter component in various frameworks. If your framework of choice is not listed here, please add it!

Contributing

NOTE: In the interest of full disclosure, this repository will be used by me to create a course on testing for which I will be paid.

The prime example is this react version:

// adds handy assertions we'll use
import '@testing-library/jest-dom/extend-expect'

// framework imports
import * as React from 'react'
import ReactDOM from 'react-dom'

// DOM Testing Library utilities
// note: if your framework does not apply updates to the DOM synchronously
// then you can use the userEventAsync export in ./user-event-async.js
// see hyperapp.test.js for an example of this.
import {getQueriesForElement} from '@testing-library/dom'
import userEvent from '@testing-library/user-event'

// the component in your framework
function Counter() {
  const [count, setCount] = React.useState(0)
  const increment = () => setCount(c => c + 1)
  return (
    <div>
      <button onClick={increment}>{count}</button>
    </div>
  )
}

// a generic "render" method that you could use for any component for
// your framework
function render(ui) {
  const container = document.createElement('div')
  document.body.appendChild(container)
  ReactDOM.render(ui, container)
  return {
    container,
    ...getQueriesForElement(container),
  }
}

// the test.
// This test _should_ look almost identical between each framework
// that's the idea that I'm trying to get across in this repo!
test('renders a counter', () => {
  const {getByText} = render(<Counter />)
  const counter = getByText('0')
  userEvent.click(counter)
  expect(counter).toHaveTextContent('1')

  userEvent.click(counter)
  expect(counter).toHaveTextContent('2')
})

If you can make your example resemble that, I would be thrilled :)

IMPORTANT Notes

I want to keep things as simple as possible, but I also want to be true to what's typical for a given framework. If your framework strongly encourages the use of TypeScript for example, then please feel free to use TypeScript (Jest should already be configured to pick it up properly).

If Jest is not the testing framework of choice for your web framework, I'd still prefer to stick with Jest. Hopefully it shouldn't make much of a difference for the test itself.

Try really hard to keep everything in a single file, even if that means authoring your component in a slightly non-typical way.

This project is setup with prettier, husky, and lint-staged. That means that when you commit, a git commit hook will automatically format the files you're changing and run the tests relevant to those files. Neat right?

LICENSE

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].