New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chai-react

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-react - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

4

bower.json
{
"name": "chai-react",
"main": "chai-react.js",
"version": "0.0.4",
"version": "1.0.0",
"authors": [

@@ -29,5 +29,5 @@ "Andrew Hanna <percyhanna@gmail.com>"

"dependencies": {
"react": "~0.10.0"
"react": "~0.12.0"
},
"homepage": "https://github.com/percyhanna/chai-react"
}

@@ -89,3 +89,3 @@ (function (chaiReact) {

chai.Assertion.addMethod('componentsWithProp', function (name, value) {
chai.Assertion.addMethod('componentsWithProp', function (name, value, match) {
var components,

@@ -100,6 +100,14 @@ component = flag(this, 'object');

if (value !== undefined) {
return comp.props[name] === value;
var prop = comp.props[name];
switch (match) {
case 'contains':
return typeof prop === 'string' && prop.indexOf(value) !== -1;
default:
return prop === value;
}
}
return name in comp.props;
return !TestUtils.isTextComponent(comp) && name in comp.props;
});

@@ -126,13 +134,22 @@

chai.Assertion.addMethod('componentsOfType', function (type) {
var actual, component = flag(this, 'object');
var components = [];
var component = flag(this, 'object');
new chai.Assertion(component).is.a.component;
inspectify(component);
components = TestUtils.scryRenderedComponentsWithType(component, type);
flag(this, 'object', components);
});
chai.Assertion.addMethod('componentsWithTag', function (tag) {
var components = [];
var component = flag(this, 'object');
new chai.Assertion(component).is.a.component;
inspectify(component);
actual = TestUtils.findAllInRenderedTree(component, function (comp) {
return TestUtils.isComponentOfType(comp, type);
});
components = TestUtils.scryRenderedDOMComponentsWithTag(component, tag);
flag(this, 'object', actual);
flag(this, 'object', components);
});

@@ -155,3 +172,3 @@

for (var i = 0; i < textComponents.length; i++) {
if (textComponents[i].props.text === text || textComponents[i].props.children === text) {
if (textComponents[i].props === text || textComponents[i].props.children === text) {
flag(this, 'object', textComponents[i]);

@@ -181,2 +198,22 @@ foundMatch = true;

chai.Assertion.addProperty('reactClass', function () {
var reactClass = flag(this, 'object');
this.assert(
React.isValidClass(reactClass),
'expected #{this} to be a valid React class, but it is not',
'expected #{this} to not be a valid React class, but it is'
);
});
chai.Assertion.addProperty('element', function () {
var element = flag(this, 'object');
this.assert(
React.isValidElement(element),
'expected #{this} to be a valid React element, but it is not',
'expected #{this} to not be a valid React element, but it is'
);
});
chai.Assertion.addMethod('triggerEvent', function (eventName, args) {

@@ -183,0 +220,0 @@ var component = flag(this, 'object');

@@ -12,3 +12,3 @@ {

],
"version": "0.0.4",
"version": "1.0.0",
"repository": {

@@ -15,0 +15,0 @@ "type": "git",

@@ -34,11 +34,9 @@ describe('chai-react', function() {

render: function () {
return (
React.DOM.div(
{ className: 'abc testing-class' },
React.DOM.span({}, 'my span text'),
'separator text',
React.DOM.span({}, 'my other span text'),
childComponent({}),
childComponent({ myVar: 5 })
)
return React.createElement(
'div',
{ className: 'abc testing-class' },
'separator text',
React.createElement('span', { className: 'my-class other-class cool' }, 'my other span text'),
childComponent({}),
childComponent({ myVar: 5 })
);

@@ -70,9 +68,8 @@ }

render: function () {
return (
React.DOM.div(
{},
React.DOM.p({}, 'Hello, this is my state: ' + this.state.myState),
React.DOM.p({}, 'Hello, this is some state: ' + this.state.someState),
React.DOM.p({ onClick: this._myClickEvent }, 'Child text')
)
return React.createElement(
'div',
{},
React.createElement('p', {}, 'Hello, this is my state: ' + this.state.myState),
React.createElement('p', {}, 'Hello, this is some state: ' + this.state.someState),
React.createElement('p', { onClick: this._myClickEvent }, 'Child text')
);

@@ -196,4 +193,34 @@ }

});
describe('contains', function () {
it('allows diving into props of a found component', function () {
var component = utils.renderIntoDocument(testComponent());
expect(component).componentsWithProp('className', 'my-class', 'contains').first.to.have.prop('className', 'my-class other-class cool');
});
});
});
describe('componentsWithTag', function () {
it('retrieves descendant components of type', function () {
var component = utils.renderIntoDocument(testComponent());
expect(component).componentsWithTag('div').to.have.length(3);
});
it('fails with a non component', function() {
expect(function () {
expect('').componentsWithTag('p');
}).to.fail('expected \'\' to be a valid React component, but it is not');
});
describe('prop', function () {
it('allows diving into props of a found component', function () {
var component = utils.renderIntoDocument(testComponent());
expect(component).componentsWithTag('div').atIndex(1).to.have.prop('children');
});
});
});
describe('componentsOfType', function () {

@@ -203,3 +230,3 @@ it('retrieves descendant components of type', function () {

expect(component).componentsOfType(React.DOM.p).to.have.length(6);
expect(component).componentsOfType(childComponent).to.have.length(2);
});

@@ -209,3 +236,3 @@

expect(function () {
expect('').componentsOfType(React.DOM.p);
expect('').componentsOfType('p');
}).to.fail('expected \'\' to be a valid React component, but it is not');

@@ -279,2 +306,24 @@ });

describe('element', function () {
it('passes with a valid element', function () {
var element = React.createElement(testComponent);
expect(element).to.be.a.element;
});
it('fails with a non element', function() {
expect('').to.not.be.a.element;
});
});
describe('reactClass', function () {
it('passes with a valid reactClass', function () {
expect(testComponent).to.be.a.reactClass;
});
it('fails with a non reactClass', function() {
expect('').to.not.be.a.reactClass;
});
});
describe('triggerEvent', function () {

@@ -281,0 +330,0 @@ it('triggers a component event', function () {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc