Registry / testing / expect-element

expect-element

JSON →
library1.1.1jsnpmunverified

expect-element is an extension for the expect assertion library that provides DOM-specific assertions for testing DOM nodes. Current stable version is 1.1.1, released under the MIT license. It adds assertions like toHaveAttribute, toHaveText, etc. This package is lightweight, requires expect as a peer dependency, and is designed for unit testing in browser or jsdom environments. It is not actively maintained (last release in 2016). Compared to alternatives like jest-dom, expect-element is simpler but lacks TypeScript support and modern updates.

npm install expect-element
INSTALL
IMPORT
SIG · EXPECT-ELEMENT
E
expect-element
testingjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

expectElement
import expectElement from 'expect-element'
const { expectElement } = require('expect-element')
Default import; named import does not exist.
expect
import expect from 'expect'
import { expect } from 'expect'
expect is a default export, not named.
expectElement (via UMD)
const expectElement = window.expectElement
UMD build available on npmcdn; attaches to window.

Demonstrates basic setup and usage of expect-element with DOM assertions.

import expect from 'expect'; import expectElement from 'expect-element'; expect.extend(expectElement); // Create a DOM element document.body.innerHTML = '<div id="foo" class="bar">Hello</div>'; const el = document.getElementById('foo'); // Assertions expect(el).toHaveAttribute('id', 'foo'); expect(el).toHaveText('Hello'); expect(el).toNotHaveAttribute('style');
Debug
Known issues
deprecatedThis package is no longer actively maintained. The last release was in 2016.
fix
Consider using jest-dom or @testing-library/jest-dom for modern DOM assertions.
affects: >=1.0.0
gotchaMust call expect.extend(expectElement) before using assertions; otherwise no custom matchers.
fix
import expectElement from 'expect-element'; expect.extend(expectElement);
affects: >=1.0.0
gotchaexpect package version must be ^1.15.1. Using a different major version may break.
fix
Ensure expect@^1.15.1 is installed.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'expect-element'
Package not installed or npm install missing expect-element.
fix
npm install expect expect-element
expect(...).toHaveAttribute is not a function
Did not call expect.extend(expectElement) before using matchers.
fix
import expectElement from 'expect-element'; expect.extend(expectElement);
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
expectrequiredPeer dependency; expect-element extends expect with DOM-specific assertions.
Agent activity
4 hits · last 30 days
node
4
Resources
expect-element — npm install expect-element · libregistry