chai-react
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "chai-react", | ||
"main": "chai-react.js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"authors": [ | ||
@@ -6,0 +6,0 @@ "Andrew Hanna <percyhanna@gmail.com>" |
@@ -142,2 +142,12 @@ (function (chaiReact) { | ||
chai.Assertion.addMethod('componentOfType', function (type) { | ||
var component = flag(this, 'object'); | ||
new chai.Assertion(component).is.a.component; | ||
inspectify(component); | ||
var found = TestUtils.findRenderedComponentWithType(component, type); | ||
flag(this, 'object', found); | ||
}); | ||
chai.Assertion.addMethod('componentsWithTag', function (tag) { | ||
@@ -155,2 +165,13 @@ var components = []; | ||
chai.Assertion.addMethod('componentWithTag', function (tag) { | ||
var component = flag(this, 'object'); | ||
new chai.Assertion(component).is.a.component; | ||
inspectify(component); | ||
var found = TestUtils.findRenderedDOMComponentWithTag(component, tag); | ||
flag(this, 'object', found); | ||
}); | ||
chai.Assertion.addMethod('textComponent', function (text) { | ||
@@ -196,12 +217,2 @@ var actual, component = flag(this, 'object'); | ||
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 () { | ||
@@ -208,0 +219,0 @@ var element = flag(this, 'object'); |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"repository": { | ||
@@ -15,0 +15,0 @@ "type": "git", |
@@ -40,3 +40,4 @@ describe('chai-react', function() { | ||
childComponent({}), | ||
childComponent({ myVar: 5 }) | ||
childComponent({ myVar: 5 }), | ||
singleComponent({}) | ||
); | ||
@@ -78,2 +79,24 @@ } | ||
var singleComponent = React.createClass({ | ||
getDefaultProps: function () { | ||
return { | ||
bar: 1 | ||
}; | ||
}, | ||
getInitialState: function () { | ||
return { | ||
foo: this.props.bar * 2 | ||
}; | ||
}, | ||
render: function () { | ||
return React.createElement( | ||
'h1', | ||
{}, | ||
React.createElement('i', {}) | ||
); | ||
} | ||
}) | ||
describe('state', function () { | ||
@@ -203,23 +226,45 @@ it('works with initial state for top-level component', function() { | ||
describe('componentsWithTag', function () { | ||
it('retrieves descendant components of type', function () { | ||
var component = utils.renderIntoDocument(testComponent()); | ||
describe('componentsWithTag', function () { | ||
it('retrieves descendant components of type', function () { | ||
var component = utils.renderIntoDocument(testComponent()); | ||
expect(component).componentsWithTag('div').to.have.length(3); | ||
}); | ||
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'); | ||
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('prop', function () { | ||
it('allows diving into props of a found component', function () { | ||
describe('componentWithTag', function () { | ||
it('retrieves descendant component of type', function () { | ||
var component = utils.renderIntoDocument(testComponent()); | ||
expect(component).componentsWithTag('div').atIndex(1).to.have.prop('children'); | ||
expect(component).componentWithTag('h1').to.not.be.undefined; | ||
}); | ||
it('fails with a non component', function() { | ||
expect(function () { | ||
expect('').componentWithTag('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).componentWithTag('h1').to.have.prop('children'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -258,2 +303,32 @@ describe('componentsOfType', function () { | ||
describe('componentOfType', function () { | ||
it('retrieves a single descendant component of type', function () { | ||
var component = utils.renderIntoDocument(testComponent()); | ||
expect(component).componentOfType(singleComponent).to.not.be.undefined; | ||
}); | ||
it('fails with a non component', function() { | ||
expect(function () { | ||
expect('').componentsOfType('p'); | ||
}).to.fail('expected \'\' to be a valid React component, but it is not'); | ||
}); | ||
describe('state', function () { | ||
it('allows diving into state of a found component', function () { | ||
var component = utils.renderIntoDocument(testComponent()); | ||
expect(component).componentOfType(singleComponent).to.have.state('foo', 2); | ||
}); | ||
}); | ||
describe('prop', function () { | ||
it('allows diving into props of a found component', function () { | ||
var component = utils.renderIntoDocument(testComponent()); | ||
expect(component).componentOfType(singleComponent).to.have.prop('bar', 1); | ||
}); | ||
}); | ||
}); | ||
describe('textComponent', function () { | ||
@@ -317,12 +392,2 @@ it('matches plain text components', function () { | ||
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 () { | ||
@@ -329,0 +394,0 @@ it('triggers a component event', function () { |
23958
528