Registry / testing / lite-fixture

lite-fixture

JSON →
library1.0.2jsnpmunverified

lite-fixture is a lightweight utility designed to create and manage temporary DOM elements for browser-based testing environments. It simplifies the setup and teardown of test fixtures, allowing developers to easily create a `sandbox` element (or multiple with specific IDs/styles) and ensure their removal using `cleanup()`. The current stable version is 1.0.2. It focuses on minimal API surface for direct DOM manipulation, making it suitable for simple unit tests that require a live DOM. While functional and stable, the package appears to be minimally maintained, with its last update several years ago, which implies a low release cadence. Its primary differentiator is its extreme simplicity and small footprint compared to more comprehensive testing frameworks.

npm install lite-fixture
INSTALL
IMPORT
SIG · LITE-FIXTURE
L
lite-fixture
testingjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sandbox
const { sandbox } = require('lite-fixture');
import { sandbox } from 'lite-fixture';
Primarily designed for CommonJS/UMD. While bundlers might allow ES module syntax, the package is CJS first.
cleanup
const { cleanup } = require('lite-fixture');
import { cleanup } from 'lite-fixture';
Crucial for removing test DOM elements to prevent side effects and memory leaks.

This example demonstrates how to create various sandbox elements with default or custom IDs and styles, add content to them, and crucially, how to clean them up after tests using `cleanup()`.

const { sandbox, cleanup } = require('lite-fixture'); // Create a default sandbox element const elSandbox1 = sandbox(); console.log('Default sandbox created with ID:', elSandbox1.id); // Create a sandbox with a custom ID const elSandbox2 = sandbox('my-custom-test-id'); console.log('Custom sandbox created with ID:', elSandbox2.id); // Create a sandbox with custom ID and style const elSandbox3 = sandbox({ id: 'hidden-test-area', style: 'display: none; border: 1px solid red; padding: 10px;' }); console.log('Hidden sandbox created with ID:', elSandbox3.id, 'and style:', elSandbox3.style.cssText); // Append content to a sandbox elSandbox1.innerHTML = '<div>Hello from default sandbox!</div>'; elSandbox2.innerHTML = '<button>Click Me</button>'; // Simulate a test... then clean up console.log('Performing test operations...'); // Clean up specific sandboxes cleanup('my-custom-test-id'); console.log('Cleaned up "my-custom-test-id" sandbox.'); cleanup('hidden-test-area'); console.log('Cleaned up "hidden-test-area" sandbox.'); // Clean up the default sandbox cleanup(); console.log('Cleaned up default sandbox.'); // Verify cleanup (this will log an error if trying to access removed elements) try { document.getElementById(elSandbox1.id); // Should be null after cleanup document.getElementById(elSandbox2.id); // Should be null after cleanup document.getElementById(elSandbox3.id); // Should be null after cleanup } catch (e) { console.error('Error accessing cleaned up elements, which is expected:', e.message); }
Debug
Known issues
gotchaFailure to call `cleanup()` after each test can lead to memory leaks, lingering DOM elements, and test pollution where subsequent tests are affected by previous ones. Always ensure `cleanup()` is invoked in your test teardown.
fix
Call `cleanup()` in an `afterEach` or `afterAll` hook of your testing framework, or manually at the end of each test.
affects: >=1.0.0
gotchaThis package is designed for browser environments. Using it directly in Node.js without a DOM simulation layer like JSDOM will result in errors related to missing `document` or `window` objects.
fix
Ensure your test environment provides a DOM (e.g., running tests in a browser or configuring JSDOM for Node.js tests).
affects: >=1.0.0
deprecatedThe package has not been updated in several years (since version 1.0.2). While functional for its core purpose, it may not be actively maintained to address new browser features, edge cases, or potential security vulnerabilities related to DOM manipulation.
fix
Evaluate if the simplicity of `lite-fixture` still meets your needs or if a more actively maintained library or testing framework's built-in fixture handling is more appropriate for modern web development.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: document is not defined
Attempting to use `lite-fixture` in a Node.js environment without a mocked or simulated browser DOM.
fix
Use a tool like JSDOM in your Node.js test setup to provide a global `document` object, or run your tests in a browser environment.
TypeError: Cannot read properties of null (reading 'remove')
This error can occur if `cleanup()` is called for an element that has already been removed, or if `cleanup` is called with an ID that does not correspond to an existing sandbox element.
fix
Ensure `cleanup()` is only called for existing sandbox elements. If using `cleanup()` without arguments, ensure there is a default sandbox. Consider wrapping `cleanup` calls in a `try...catch` block or checking for element existence before cleanup if multiple cleanup attempts are possible.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
lite-fixture — npm install lite-fixture · libregistry