Unit Tests
Uncompiled Dim apps (dimui, dim-boilerplate) test the same way they run: classic scripts in a real browser, with no Babel or bundler. Dim ships DimTest — a tiny IIFE harness that exposes window.DimTest.
Framework unit tests for Dim’s own src/ use Jest (npm test in the dim repo). Do not load BP.module apps through Jest.
Load order
Serve the app over HTTP, then in runTests.html (or a minimal harness page):
dim.test.global.js— first, so splash/toolbar appear- Optional
dim.cover.global.js— line coverage - Optional
dim.verify.global.js— contracts prover - Dim IIFE (
dim.global.jsordim.wasm.global.js) - App
runtime.js+ modules - Colocated
*.test.jsscripts (explicit list, not glob discovery) DimTest.run()at the end of boot
CDN:
https://positive-intentions.github.io/dim/lib/dim.test.global.js
https://positive-intentions.github.io/dim/lib/dim.cover.global.js
https://positive-intentions.github.io/dim/lib/dim.verify.global.js
Source of truth: examples/app-test/dim-test.global.js.
Writing a unit test
DimTest.test("counter mounts", async () => {
const el = await DimTest.mount("my-counter");
DimTest.expect(DimTest.shadowText(el)).toContain("0");
});
| API | Role |
|---|---|
test(name, fn) | Register a unit spec |
expect(actual) | toBe, toEqual, toBeTruthy, toContain, toBeGreaterThan |
mount(tag, props?) | Create element in #dim-test-root, await updateComplete |
shadowText(el) | Normalized shadow text |
clearFixture() | Reset the fixture DOM |
run() / rerun() | Execute suite, paint report |
splash(msg) | Boot splash message |
There is no Jest-style describe / it — only test / e2e.
Specs live next to source (e.g. note-item.test.js beside note-item.js) and call BP.require(...) + DimTest.mount(...) against real modules. runTests.html maintains an explicit manifest of script URLs.
Minimal demo
<script src="https://positive-intentions.github.io/dim/lib/dim.global.js"></script>
<script src="https://positive-intentions.github.io/dim/lib/dim.test.global.js"></script>
<script>
DimTest.test("counter mounts", async () => {
const el = await DimTest.mount("my-counter");
DimTest.expect(DimTest.shadowText(el)).toContain("0");
});
DimTest.run(); // paints a report; sets window.__DIM_TEST__
</script>
Try examples/app-test/ (?impl=js or ?impl=wasm). Full suites: dim-boilerplate runTests.html, dimui runTests.html, dimurl runTests.html.
CI contract
After run(), DimTest sets window.__DIM_TEST__:
{ done, passed, failed, results, coverage, coverageE2e, verification, … }
Playwright (in GitHub Actions only — apps still have no package.json bundler) opens runTests.html, waits for done, and fails if failed > 0. Often runs both ?impl=js and ?impl=wasm.
Framework Jest (dim repo)
For contributors working on Dim itself:
npm test # Jest + jsdom against src/
npm run test:wasm # parity suites on WASM
npm run test:rust # cargo
Pattern: import from src/core, define() + html, mount helper, await el.updateComplete. Canonical example: define.test.js.