
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
chai-shallowly
Advanced tools
A chai assertion plugin for enzyme. The goal of this assertion plugin is to allow you to use a chai-like synax with enzyme.
The syntax looks like this:
let component = <Foo />;
expect(component).to.shallowly.haveClass("this-is-a-class");
If you want to shallowly render something and use this API you
must include the keyword shallowly
. The rest should work as
you expect.
NOTE: This does not change the context of chai.
expect(component).to.shallowly.be.ok
will check against component
not the shallow version of it. This is an intentional design choice.
Enzyme is currently not expecting to be bundled in to one large file. This causes problems with Karma and Webpack. You will likely see hundreds of nearly nonsensical error messages that boil down to a few things:
Here is the config we used (you can check out the entire config in the source):
externals: {
jsdom: "window",
cheerio: "window",
"react/lib/ExecutionEnvironment": true,
"react/lib/ReactContext": true
},
resolve: {
alias: {
sinon: require.resolve("sinon/pkg/sinon")
}
},
module: {
noParse: [
/node_modules\/sinon\//
]
}
If you want Enzyme (and chai-enzyme) to work with Karma and Webpack you will need to add these to your test-only config.
You can check out the tests for more explicit coverage and usages. Here I will cover what we have done so far.
// hasClass
expect(shallow(component).hasClass("class")).to.be.true;
expect(component).to.shallowly.haveClass("class");
// text
expect(shallow(component).text()).to.equal("text");
expect(component).to.shallowly.have.text().equal("text");
// is
expect(shallow(component).is("div")).to.be.true;
expect(component).to.shallowly.match("div");
// type
expect(shallow(component).type("div")).to.be.true;
expect(component).to.shallowly.have.type("div");
// find
expect(shallow(component).find(".foo")).to.have.length(2);
expect(component).to.shallowly.find(".foo").to.have.length(2);
// filter
expect(shallow(component).find(".foo").filter(".bar")).to.have.length(1);
expect(component).to.shallowly.find(".foo").filter(".bar").to.have.length(1);
// not
expect(shallow(component).find(".foo").not(".bar")).to.have.length(1);
expect(component).to.shallowly.find(".foo").without(".bar").to.have.length(1);
// contains
expect(shallow(component).contains("div")).to.be.true;
expect(component).to.shallowly.containJSX("div");
// state
expect(shallow(component).state(state)).to.eql({"foo": "bar"});
expect(component).to.shallowly.have.state(state).eql({"foo": "bar"});
// props
expect(shallow(component).instance().props(propKey)).to.eql(propValue);
expect(component).to.shallowly.have.props(propKey).eql(propValue);
// simulate
/* all of this */
var shallowComponent = shallow(component);
shallowComponent.simulate("click");
expect(shallowComponent.state()).to.eql({"state":"clicked"});
/* vs */
expect(component).to.shallowly.on("click").have.state().eql({"state":"clicked"});
// setState / setProps
var shallowComponent = shallow(component);
shallowComponent.setState(state);
expect(shallowComponent.state()).to.equal(state);
expect(component).to.shallowly.withState(state).to.have.state().equal(state);
FAQs
A Chai assertion frame work for Enzyme
The npm package chai-shallowly receives a total of 198 weekly downloads. As such, chai-shallowly popularity was classified as not popular.
We found that chai-shallowly 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.