Skip to content

osmoscraft/web-testing-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web Testing Library

Minimalist testing library that runs in the browser.

  • JSDOMReal DOM
  • What you test is what you get

Note: This library is in experimental stage. It does not integrate with any CI/CD yet. This library only exports TypeScript. So you will need a modern compiler to use it. Currently only supporting vite and esbuild.

Get started

npm i -D @osmoscraft/web-testing-library
// my-test.ts
import { describe, expect, it } from "@osmoscraft/web-testing-library";

export const testAddition = describe("Browser API", () => {
  it("Indexed DB/Has indexedDB", async () => {
    await expect(1+1).toEqual(2);
  });
});

Please make sure to use await in frontend of each expect or the error reporting may not be able to surface all failed tests

// run-tests.ts
import { reportSummary } from "@osmoscraft/web-testing-library";
import { testAddition } from "./my-test";

async function testAll() {
  await testAddition();
  reportSummary();
}

testAll();

Reference the run-tests.ts using your preferred bundler.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="stylesheet" href="tests.css" />
    <title>test page</title>
  </head>
  <body>
    <!-- Include other dependencies of your testing code here -->

    <script type="module" src="run-tests.ts"></script>
  </body>
</html>

API reference

import { describe, expect, it, beforeEach, afterEach, beforeAll, afterAll } from "@osmoscraft/web-testing-library";

const runTestSuite = describe("hello world", () => {

  it("spec name", async () => {
    // simple assertion
    await expect("hello").toEqual("hello");
    
    // simple error
    await expect(() => throw new Error()).toThrow();
    
    // negation
    await expect(true).not.toEqual(false);
    await expect(() => {}).not.toThrow();
  });

});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published