File tree Expand file tree Collapse file tree 5 files changed +24
-13
lines changed
Expand file tree Collapse file tree 5 files changed +24
-13
lines changed Original file line number Diff line number Diff line change 3333 * [ equals(node)] ( /docs/api/ShallowWrapper/equals.md )
3434 * [ every(selector)] ( /docs/api/ShallowWrapper/every.md )
3535 * [ everyWhere(predicate)] ( /docs/api/ShallowWrapper/everyWhere.md )
36- * [ exists()] ( /docs/api/ShallowWrapper/exists.md )
36+ * [ exists([ selector ] )] ( /docs/api/ShallowWrapper/exists.md )
3737 * [ filter(selector)] ( /docs/api/ShallowWrapper/filter.md )
3838 * [ filterWhere(predicate)] ( /docs/api/ShallowWrapper/filterWhere.md )
3939 * [ find(selector)] ( /docs/api/ShallowWrapper/find.md )
9191 * [ detach()] ( /docs/api/ReactWrapper/detach.md )
9292 * [ every(selector)] ( /docs/api/ReactWrapper/every.md )
9393 * [ everyWhere(predicate)] ( /docs/api/ReactWrapper/everyWhere.md )
94- * [ exists()] ( /docs/api/ReactWrapper/exists.md )
94+ * [ exists([ selector ] )] ( /docs/api/ReactWrapper/exists.md )
9595 * [ filter(selector)] ( /docs/api/ReactWrapper/filter.md )
9696 * [ filterWhere(predicate)] ( /docs/api/ReactWrapper/filterWhere.md )
9797 * [ find(selector)] ( /docs/api/ReactWrapper/find.md )
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import isEqual from 'lodash.isequal';
88import {
99 mount ,
1010 render ,
11- ReactWrapper ,
11+ ReactWrapper , shallow ,
1212} from 'enzyme' ;
1313import {
1414 ITERATOR_SYMBOL ,
@@ -4753,6 +4753,14 @@ describeWithDOM('mount', () => {
47534753 } ) ;
47544754 } ) ;
47554755 describe ( 'with argument' , ( ) => {
4756+ it ( 'throws on invalid EnzymeSelector' , ( ) => {
4757+ const wrapper = shallow ( < div /> ) ;
4758+
4759+ expect ( ( ) => wrapper . exists ( null ) ) . to . throw ( TypeError ) ;
4760+ expect ( ( ) => wrapper . exists ( undefined ) ) . to . throw ( TypeError ) ;
4761+ expect ( ( ) => wrapper . exists ( 45 ) ) . to . throw ( TypeError ) ;
4762+ expect ( ( ) => wrapper . exists ( { } ) ) . to . throw ( TypeError ) ;
4763+ } ) ;
47564764 it ( 'returns .find(arg).exists() instead' , ( ) => {
47574765 const wrapper = mount ( < div /> ) ;
47584766 const fakeFindExistsReturnVal = Symbol ( 'fake .find(arg).exists() return value' ) ;
Original file line number Diff line number Diff line change @@ -4553,6 +4553,15 @@ describe('shallow', () => {
45534553 } ) ;
45544554 } ) ;
45554555 describe ( 'with argument' , ( ) => {
4556+ it ( 'throws on invalid EnzymeSelector' , ( ) => {
4557+ const wrapper = shallow ( < div /> ) ;
4558+
4559+ expect ( ( ) => wrapper . exists ( null ) ) . to . throw ( TypeError ) ;
4560+ expect ( ( ) => wrapper . exists ( undefined ) ) . to . throw ( TypeError ) ;
4561+ expect ( ( ) => wrapper . exists ( 45 ) ) . to . throw ( TypeError ) ;
4562+ expect ( ( ) => wrapper . exists ( { } ) ) . to . throw ( TypeError ) ;
4563+ } ) ;
4564+
45564565 it ( 'returns .find(arg).exists() instead' , ( ) => {
45574566 const wrapper = shallow ( < div /> ) ;
45584567 const fakeFindExistsReturnVal = Symbol ( 'fake .find(arg).exists() return value' ) ;
Original file line number Diff line number Diff line change @@ -1077,10 +1077,7 @@ class ReactWrapper {
10771077 * @returns {boolean }
10781078 */
10791079 exists ( selector = null ) {
1080- if ( arguments . length > 0 && typeof selector !== 'string' ) {
1081- throw new TypeError ( '`selector` argument must be a string, if present.' ) ;
1082- }
1083- return typeof selector === 'string' ? this . find ( selector ) . exists ( ) : this . length > 0 ;
1080+ return arguments . length > 0 ? this . find ( selector ) . exists ( ) : this . length > 0 ;
10841081 }
10851082
10861083 /**
Original file line number Diff line number Diff line change @@ -740,7 +740,7 @@ class ShallowWrapper {
740740 /**
741741 * Finds every node in the render tree of the current wrapper that matches the provided selector.
742742 *
743- * @param {String|Function } selector
743+ * @param {String|Function|Object } selector
744744 * @returns {ShallowWrapper }
745745 */
746746 find ( selector ) {
@@ -1329,14 +1329,11 @@ class ShallowWrapper {
13291329 * Returns true if the current wrapper has nodes. False otherwise.
13301330 * If called with a selector it returns `.find(selector).exists()` instead.
13311331 *
1332- * @param {String|Function } selector (optional)
1332+ * @param {String|Function|Object } selector (optional)
13331333 * @returns {boolean }
13341334 */
13351335 exists ( selector = null ) {
1336- if ( arguments . length > 0 && typeof selector !== 'string' ) {
1337- throw new TypeError ( '`selector` argument must be a string, if present.' ) ;
1338- }
1339- return typeof selector === 'string' ? this . find ( selector ) . exists ( ) : this . length > 0 ;
1336+ return arguments . length > 0 ? this . find ( selector ) . exists ( ) : this . length > 0 ;
13401337 }
13411338
13421339 /**
You can’t perform that action at this time.
0 commit comments