Search code examples
javascripttesting-library

Using Testing Library in standalone


I was trying to do something similar to the Testing Playground but I don't know which JavaScript file to include to have access to all the Testing Library native functions.

The goal is to be able to run queries like getAllByRole in the browser console. I don't want to have a Node project running. I just want a basic HTML file that includes the Testing Library JavaScript file so I can run its functions in the browser console.


Solution

  • To start without any bundle tools, try the @testing-library/dom library from the skypack CDN which prepares npm packages for native JavaScript ES6 import usage. (It's the one being used in codepen.io)

    <script type="module">
      import { getByRole } from "https://cdn.skypack.dev/@testing-library/[email protected]"; 
      console.log(getByRole)
    </script>