Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@
"react": "^0.14.0",
"react-addons-test-utils": "^0.14.0"
},
"dependencies": {}
"dependencies": {
"lodash.get": "^3.7.0",
"lodash.isequal": "^3.0.4"
}
}
60 changes: 28 additions & 32 deletions specs/find-all-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,36 @@ import {findAll} from '../src';
import {createRenderer} from 'react-addons-test-utils';
import React from 'react';

class OtherComponent extends React.Component {
render() {
return (
<div className='other-component' />
);
}
function OtherComponent() {
return (
<div className='other-component' />
);
}

class TestWithForm extends React.Component {
render() {
return (
<div className='test-class'>
<span />
<div className='test-class test-class--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class3 test-class3--modified' />
<form
action='/'
method='post'>
<input
id='test'
name='test'
type='text' />
<input
id='test2'
name='test2'
type='text' />
<button>Send</button>
</form>
<OtherComponent />
<span>Some content</span>
</div>
);
}
function TestWithForm() {
return (
<div className='test-class'>
<span />
<div className='test-class test-class--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class3 test-class3--modified' />
<form
action='/'
method='post'>
<input
id='test'
name='test'
type='text' />
<input
id='test2'
name='test2'
type='text' />
<button>Send</button>
</form>
<OtherComponent />
<span>Some content</span>
</div>
);
}

describe('`findAll`', function() {
Expand Down
24 changes: 11 additions & 13 deletions specs/find-all-with-class-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import React from 'react';

describe('`findAllWithClass`', function() {
beforeEach(function() {
class TestWithClasses extends React.Component {
render() {
return (
<div className='test-class'>
<span />
<div className='test-class test-class--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class3 test-class3--modified' />
<span>Some content</span>
</div>
);
}
function TestWithClasses() {
return (
<div className='test-class'>
<span />
<div className='test-class test-class--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class3 test-class3--modified' />
<span>Some content</span>
</div>
);
}

this.renderer = createRenderer();
Expand Down
70 changes: 70 additions & 0 deletions specs/find-all-with-prop-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {findAllWithProp} from '../src';
import {createRenderer} from 'react-addons-test-utils';
import React from 'react';

describe('`findAllWithProp`', function() {
beforeEach(function() {
function TestComponent() {
const deepObject = {
top: {
deep: true
}
};

return (
<div className='test-class'>
<div sameProp='same' testProp1={1} />
<div sameProp='same' testProp2='testProp2Value' />
<div sameProp='same' testProp2='testProp2Value' testProp3={deepObject} />
<div sameProp='same' testProp3={deepObject} />
</div>
);
}

this.renderer = createRenderer();
this.renderer.render(<TestComponent />);
this.tree = this.renderer.getRenderOutput();
});

it('should find one component with `testProp1` equal to `1`', function() {
const found = findAllWithProp(this.tree, 'testProp1', 1);

expect(found.length).toBe(1);
});

it('should find no component with `testProp1` equal to `2`', function() {
const found = findAllWithProp(this.tree, 'testProp1', 2);

expect(found.length).toBe(0);
});

it('should find two components with `testProp3.top` equal to `{deep:true}`', function() {
const found = findAllWithProp(this.tree, 'testProp3.top', {deep:true});

expect(found.length).toBe(2);
});

it('should find no components with `testProp3.top` equal to `{deep:false}`', function() {
const found = findAllWithProp(this.tree, 'testProp3.top', {deep:false});

expect(found.length).toBe(0);
});

it('should find four components with `sameProp` equal to `same`', function() {
const found = findAllWithProp(this.tree, 'sameProp', 'same');

expect(found.length).toBe(4);
});

it('should find no components with `sameProp` equal to `not-same`', function() {
const found = findAllWithProp(this.tree, 'sameProp', 'not-same');

expect(found.length).toBe(0);
});

it('should find no components with non-existant prop', function() {
const found = findAllWithProp(this.tree, 'blahblahblah', 1);

expect(found.length).toBe(0);
});
});
52 changes: 23 additions & 29 deletions specs/find-all-with-type-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@ import {findAllWithType} from '../src';
import {createRenderer} from 'react-addons-test-utils';
import React from 'react';

class OtherComponent extends React.Component {
render() {
return (
<div className='other-component' />
);
}
function OtherComponent() {
return (
<div className='other-component' />
);
}

class YetAnotherComponent extends React.Component {
render() {
return (
<div className='other-component' />
);
}
function YetAnotherComponent() {
return (
<div className='other-component' />
);
}

class TestWithTypes extends React.Component {
render() {
return (
<div className='test-class'>
<span />
<div className='test-class test-class--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class3 test-class3--modified' />
<OtherComponent test={1} />
<OtherComponent test={2} />
<OtherComponent test={3} />
<YetAnotherComponent test={1} />
<YetAnotherComponent test={2} />
<YetAnotherComponent test={3} />
</div>
);
}
function TestWithTypes() {
return (
<div className='test-class'>
<span />
<div className='test-class test-class--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class3 test-class3--modified' />
<OtherComponent test={1} />
<OtherComponent test={2} />
<OtherComponent test={3} />
<YetAnotherComponent test={1} />
<YetAnotherComponent test={2} />
<YetAnotherComponent test={3} />
</div>
);
}

describe('`findAllWithType`', function() {
Expand Down
22 changes: 10 additions & 12 deletions specs/find-with-class-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import React from 'react';

describe('`findWithClass`', function() {
beforeEach(function() {
class TestWithClasses extends React.Component {
render() {
return (
<div className='test-class'>
<span />
<div className='test-class test-class--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class3 test-class3--modified' />
<span>Some content</span>
</div>
);
}
function TestWithClasses() {
return (
<div className='test-class'>
<span />
<div className='test-class test-class--modified' />
<div className='test-class2 test-class2--modified' />
<div className='test-class3 test-class3--modified' />
<span>Some content</span>
</div>
);
}

this.renderer = createRenderer();
Expand Down
76 changes: 76 additions & 0 deletions specs/find-with-prop-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {findWithProp} from '../src';
import {createRenderer} from 'react-addons-test-utils';
import React from 'react';

describe('`findWithProp`', function() {
beforeEach(function() {
function TestComponent() {
const deepObject = {
top: {
deep: true
}
};

const deepArray = [{
name: 'Dave'
}, {
name: 'Sarah'
}, {
name: 'John'
}];

return (
<div className='test-class'>
<div sameProp='same' testProp1={1} />
<div sameProp='same' testProp2='testProp2Value' />
<div sameProp='same' testProp3={deepObject} />
<div sameProp='same' testProp4={deepArray} />
</div>
);
}

this.renderer = createRenderer();
this.renderer.render(<TestComponent />);
this.tree = this.renderer.getRenderOutput();
});

it('should find component with `testProp1` equal to `1`', function() {
expect(() => findWithProp(this.tree, 'testProp1', 1)).not.toThrow();
});

it('should not find component with `testProp1` equal to `2`', function() {
expect(() => findWithProp(this.tree, 'testProp1', 2)).toThrow();
});

it('should find component with `testProp2` equal to `testProp2Value`', function() {
expect(() => findWithProp(this.tree, 'testProp2', 'testProp2Value')).not.toThrow();
});

it('should not find component with `testProp2` equal to `NOTtestProp2Value`', function() {
expect(() => findWithProp(this.tree, 'testProp2', 'NOTtestProp2Value')).toThrow();
});

it('should find component with `testProp3.top` equal to `{deep:true}`', function() {
expect(() => findWithProp(this.tree, 'testProp3.top', {deep:true})).not.toThrow();
});

it('should not find component with `testProp3.top` equal to `{deep:false}`', function() {
expect(() => findWithProp(this.tree, 'testProp3.top', {deep:false})).toThrow();
});

it('should find component with `testProp4[1].name` equal to `{name: Sarah}`', function() {
expect(() => findWithProp(this.tree, 'testProp4[1]', {name: 'Sarah'})).not.toThrow();
});

it('should find component with `testProp4[1].name` equal to `{name: Chris}`', function() {
expect(() => findWithProp(this.tree, 'testProp4[1]', {name: 'Chris'})).toThrow();
});

it('should not find exactly one component with `sameProp` equal to `same`', function() {
expect(() => findWithProp(this.tree, 'sameProp', 'same')).toThrow();
});

it('should find no components with non-existant prop', function() {
expect(() => findWithProp(this.tree, 'blahblahblah', 1)).toThrow();
});
});
30 changes: 13 additions & 17 deletions specs/find-with-ref-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@ import {findWithRef} from '../src';
import {createRenderer} from 'react-addons-test-utils';
import React from 'react';

class OtherComponent extends React.Component {
render() {
return (
<div className='other-component' />
);
}
function OtherComponent() {
return (
<div className='other-component' />
);
}

class TestWithRefs extends React.Component {
render() {
return (
<div className='test-class'>
<span />
<div className='div-ref-class' ref='div-ref' />
<input className='input-ref-class' ref='input-ref' />
<OtherComponent ref='other-component-ref' test='test' />
</div>
);
}
function TestWithRefs() {
return (
<div className='test-class'>
<span />
<div className='div-ref-class' ref='div-ref' />
<input className='input-ref-class' ref='input-ref' />
<OtherComponent ref='other-component-ref' test='test' />
</div>
);
}

describe('`findWithRef`', function() {
Expand Down
Loading