Testing Library

Testing Library

  • Docs
  • Recipes
  • Help
  • Blog

›Svelte Testing Library

Getting Started

  • Introduction
  • Guiding Principles
  • Using Fake Timers

Frameworks

    DOM Testing Library

    • Introduction
    • Install
    • Example
    • Setup
    • Queries
    • Firing Events
    • Async Utilities
    • Helpers
    • Configuration
    • FAQ
    • Cheatsheet

    React Testing Library

    • Introduction
    • Example
    • Setup
    • API
    • Migrate from Enzyme
    • FAQ
    • Cheatsheet

    Reason Testing Library

    • Introduction
    • Examples

    React Native Testing Library

    • Introduction
    • Example
    • Setup

    Vue Testing Library

    • Introduction
    • Examples
    • Setup
    • API
    • Cheatsheet
    • FAQ

    Marko Testing Library

    • Introduction
    • Setup
    • API

    Angular Testing Library

    • Introduction
    • Examples
    • API

    Preact Testing Library

    • Introduction
    • Example
    • API
    • Learn

    Svelte Testing Library

    • Introduction
    • Setup
    • Example
    • API
  • Cypress Testing Library
  • Puppeteer Testing Library
  • Testcafe Testing Library
  • Nightwatch Testing Library

Ecosystem

  • user-event
  • jest-dom
  • bs-jest-dom
  • jest-native
  • react-select-event
  • eslint-plugin-testing-library
  • eslint-plugin-jest-dom
  • riot-testing-library
  • jasmine-dom
Edit

Setup

We recommend using Jest but you're free to use the library with any testing framework and runner you're comfortable with.

Jest

  1. Install Jest

    npm install --save-dev jest
    
  2. Add the following to your package.json

    {
      "scripts": {
        "test": "jest src",
        "test:watch": "npm run test -- --watch"
      }
    }
    
  3. You'll need to compile the Svelte components before using them in Jest, so we need to install svelte-jester

    npm install --save-dev svelte-jester
    
  4. Add the following Jest configuration to your package.json

    {
      "jest": {
        "transform": {
          "^.+\\.svelte$": "svelte-jester"
        },
        "moduleFileExtensions": ["js", "svelte"]
      }
    }
    
  5. This is optional but it is recommended, you can install jest-dom to add handy assertions to Jest

    5.1 Install jest-dom

    npm install --save-dev @testing-library/jest-dom
    

    5.2 Add the following to your Jest configuration in package.json

    {
      "setupFilesAfterEnv": ["@testing-library/jest-dom/extend-expect"]
    }
    
  6. Create your component + test file (checkout the rest of the docs to see how) and run it

    npm run test
    

Typescript

To use Typescript, you'll need to install and configure svelte-preprocess and ts-jest. For full instructions, see the svelte-jester docs.

Babel / Preprocessors

If you'd like to also include Babel or any Svelte preprocessors then simply follow the instructions over at svelte-jester.

Last updated on 9/2/2020
← IntroductionExample →
  • Jest
  • Typescript
  • Babel / Preprocessors
Testing Library
Docs
Getting StartedExamplesAPIHelp
Community
BlogStack OverflowDiscord
More
StarGitHubEdit Docs on GitHubHosted by Netlify
Copyright © 2018-2020 Kent C. Dodds and contributors