Skip to content
Merged
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
4 changes: 2 additions & 2 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* [equals(node)](/docs/api/ShallowWrapper/equals.md)
* [every(selector)](/docs/api/ShallowWrapper/every.md)
* [everyWhere(predicate)](/docs/api/ShallowWrapper/everyWhere.md)
* [exists()](/docs/api/ShallowWrapper/exists.md)
* [exists([selector])](/docs/api/ShallowWrapper/exists.md)
* [filter(selector)](/docs/api/ShallowWrapper/filter.md)
* [filterWhere(predicate)](/docs/api/ShallowWrapper/filterWhere.md)
* [find(selector)](/docs/api/ShallowWrapper/find.md)
Expand Down Expand Up @@ -91,7 +91,7 @@
* [detach()](/docs/api/ReactWrapper/detach.md)
* [every(selector)](/docs/api/ReactWrapper/every.md)
* [everyWhere(predicate)](/docs/api/ReactWrapper/everyWhere.md)
* [exists()](/docs/api/ReactWrapper/exists.md)
* [exists([selector])](/docs/api/ReactWrapper/exists.md)
* [filter(selector)](/docs/api/ReactWrapper/filter.md)
* [filterWhere(predicate)](/docs/api/ReactWrapper/filterWhere.md)
* [find(selector)](/docs/api/ReactWrapper/find.md)
Expand Down
8 changes: 8 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4753,6 +4753,14 @@ describeWithDOM('mount', () => {
});
});
describe('with argument', () => {
it('throws on invalid EnzymeSelector', () => {
const wrapper = mount(<div />);

expect(() => wrapper.exists(null)).to.throw(TypeError);
expect(() => wrapper.exists(undefined)).to.throw(TypeError);
expect(() => wrapper.exists(45)).to.throw(TypeError);
expect(() => wrapper.exists({})).to.throw(TypeError);
});
it('returns .find(arg).exists() instead', () => {
const wrapper = mount(<div />);
const fakeFindExistsReturnVal = Symbol('fake .find(arg).exists() return value');
Expand Down
9 changes: 9 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4553,6 +4553,15 @@ describe('shallow', () => {
});
});
describe('with argument', () => {
it('throws on invalid EnzymeSelector', () => {
const wrapper = shallow(<div />);

expect(() => wrapper.exists(null)).to.throw(TypeError);
expect(() => wrapper.exists(undefined)).to.throw(TypeError);
expect(() => wrapper.exists(45)).to.throw(TypeError);
expect(() => wrapper.exists({})).to.throw(TypeError);
});

it('returns .find(arg).exists() instead', () => {
const wrapper = shallow(<div />);
const fakeFindExistsReturnVal = Symbol('fake .find(arg).exists() return value');
Expand Down
9 changes: 3 additions & 6 deletions packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class ReactWrapper {
/**
* Finds every node in the render tree of the current wrapper that matches the provided selector.
*
* @param {String|Function} selector
* @param {String|Function|Object} selector
* @returns {ReactWrapper}
*/
find(selector) {
Expand Down Expand Up @@ -1073,14 +1073,11 @@ class ReactWrapper {
* Returns true if the current wrapper has nodes. False otherwise.
* If called with a selector it returns `.find(selector).exists()` instead.
*
* @param {String|Function} selector (optional)
* @param {String|Function|Object} selector (optional)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature for find is * @param {String|Function} selector - should that be changed, or should this one stay the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about what you're asking:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that the jsdoc comment for find in both ShallowWrapper and ReactWrapper say "string or function" - so it seems like it should be "string or function or object" as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it:

Am I missing something?

* @returns {boolean}
*/
exists(selector = null) {
if (arguments.length > 0 && typeof selector !== 'string') {
throw new TypeError('`selector` argument must be a string, if present.');
}
return typeof selector === 'string' ? this.find(selector).exists() : this.length > 0;
return arguments.length > 0 ? this.find(selector).exists() : this.length > 0;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ class ShallowWrapper {
/**
* Finds every node in the render tree of the current wrapper that matches the provided selector.
*
* @param {String|Function} selector
* @param {String|Function|Object} selector
* @returns {ShallowWrapper}
*/
find(selector) {
Expand Down Expand Up @@ -1329,14 +1329,11 @@ class ShallowWrapper {
* Returns true if the current wrapper has nodes. False otherwise.
* If called with a selector it returns `.find(selector).exists()` instead.
*
* @param {String|Function} selector (optional)
* @param {String|Function|Object} selector (optional)
* @returns {boolean}
*/
exists(selector = null) {
if (arguments.length > 0 && typeof selector !== 'string') {
throw new TypeError('`selector` argument must be a string, if present.');
}
return typeof selector === 'string' ? this.find(selector).exists() : this.length > 0;
return arguments.length > 0 ? this.find(selector).exists() : this.length > 0;
}

/**
Expand Down