Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
chai-react-element
Advanced tools
This library provides chaining behavior and allows nested assertions using the include
language chain for React-style VDOMs. Assertions are made against unrendered (or shallow-rendered) elements, making for lighter tests that do not rely on a DOM (be it fake or real).
By using duck typing, the plugin can accept a ReactElement
or any object that has the same properties as a ReactElement
:
type
propertyprops
property that is an object, or no props
property at allThere are several other Chai plugins intended to help make assertions on React objects. This library differs from the alternatives in the following manners:
expect(<div>hello</div>).to.have.text('hello');
expect(<div></div>).to.have.elementOfType('div')
expect(<div data-foo="bar"></div>).to.have.prop('data-foo', 'bar');
expect(<div><div data-foo="bar"></div></div>).to.include.prop('data-foo', 'bar');
expect(<div><span>hello</span></div>).to.include.elementOfType('span').with.text('hello');
The chain works non-eagerly, i.e. does not match against the first element found, meaning that this assertion will hold:
expect(<div><span></span><span>hello</span></div>).to.include.elementOfType('span').with.text('hello');
$ npm install chai-react-element
Note: currently only React 0.13.x is supported. Work on moving to React 0.14.x will commence in the near future.
import chai, {expect} from 'chai';
import matcher from 'chai-react-element';
chai.use(matcher);
The plugin is exported as an ES6 module. If using ES5, please use:
chai.use(require('chai-react-element').default);
Chainable behavior is only supported for the .elementOfType
assertion. This means that the .prop
and .text
assertions can only be used at the end of an assertion chain, and the following style is unsupported:
expect(<div data-foo="bar"><span></span></div>).to.have.prop('data-foo', 'bar').with.an.elementOfType('span')
Negative assertions may behave unexpectedly for nested assertions. For instance, the following example will fail as soon as it encounters the first span
element, while it should fail only on the second element.
expect(<div><span></span><span data-foo="bar"></span></div>).to.not.include.elementOfType('span').with.prop('data-foo');
This project uses Gulp for build and tests, and webpack-dev-server
for running and debugging in-browser.
To install the project, just run npm install
.
To start the development environment, run npm start
, or, if you have Gulp installed globally, gulp dev
. This runs tests using Mocha and in addition starts webpack-dev-server
on port 8080. To run the tests, use npm test
(or gulp test
).
Please open an issue on the project's GitHub repo for any problem you might find. Please refrain from creating pull requests before discussing your problem in an issue.
Please try to develop your submission using Test-Driven Development. At the very least, make sure that your changes are well-covered with tests, and that your code is clean.
FAQs
A suite of Chai assertions for ReactElement VDOMs
The npm package chai-react-element receives a total of 18 weekly downloads. As such, chai-react-element popularity was classified as not popular.
We found that chai-react-element demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.