Frustration-free automated UI testing in a real browser, with a familiar and intuitive syntax
Test Real Use Cases in Real Browsers
Increase confidence in your code by writing tests that mimic real user behavior and running them in a real browser. When things go wrong, debug your tests using browser developer tools.
Build Inclusive UIs with Accessibility Testing Features
One-of-a-kind tools like Accessibility Tree Snapshots as well as features built into Jest and Testing Library make it easier to understand, improve, and maintain the accessibility of your interfaces.
Get Up to Speed Quickly With Familiar Tools
Pleasantest super-charges tools like Jest and Testing Library that you may already be familiar with, while avoiding the drawbacks of simulated browsers.
Getting Started
Follow these six quick steps to get up and running with Pleasantest. For more information, check out the documentation on GitHub.
Install Jest and Pleasantest
Pleasantest integrates with Jest tests. If you haven't set up Jest yet, here is Jest's getting started guide.
You’ll need to install Jest and Pleasantest:
npm i -D jest pleasantestWrite Your First Test
Now you’re ready to write your first test! Wrapping your test callback with
withBrowser
allows you to hook into a real browser with Pleasantest:ts// If you want to use module imports you’ll need to configure// Jest and Babel to use ESM// See https://jestjs.io/docs/getting-started#using-babelconst { withBrowser } = require('pleasantest');test('test name',withBrowser(async ({ utils, screen, user }) => {// Your test code here}),);Add UI Markup to Your Test
Once you’ve created a test there are three ways to insert markup:
ts// For JS frameworks you can run arbitrary JavaScript// (./app could be a .js, .jsx .ts, or .tsx file)await utils.runJS(`import { App } from './app'import { render } from 'react-dom'render(<App/>, document.body)`);// You can also insert HTML// (This works well with templating languages)await utils.injectHTML('<h1>Find Hikes</h1>');// Tests can also be run by navigating to URLs within your app:await page.goto('http://localhost:3000/hikes');Interact With Your App In a Real Browser
Pleasantest comes prepackaged with helpful utilities to find and interact with elements like a real user:
tsconst locationInput = await screen.getByRole('textbox', {name: 'Pick a Location'});const submitButton = await screen.getByRole('button', {name: 'Find Hikes'});await user.type(locationInput, 'Portland, Oregon');await user.click(submitButton);Make Assertions Against the DOM
Use jest-dom’s intuitive syntax to confirm your interface responds correctly to user actions:
tsawait expect(submitButton).toHaveFocus();await expect(hikeResults).toBeVisible();Run Your Tests
Now you can use the Jest CLI commands to run your tests. The
testTimeout
flag tells Jest to allow the test to run for up to 10 seconds, which is necessary for the first time Pleasantest starts the browser.npx jest --testTimeout=10000