Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with a CSS parser for selector parsing #1086

Merged
merged 25 commits into from
Sep 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Use new selector API in mount and shallow wrappers
  • Loading branch information
Brandon Dail committed Sep 13, 2017
commit 0d4a7eb149e4bb5ece627781c4dc99d9dc8fa94e
12 changes: 4 additions & 8 deletions packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import flatten from 'lodash/flatten';
import unique from 'lodash/uniq';
import compact from 'lodash/compact';

import ComplexSelector from './ComplexSelector';
import createWrapperComponent from './ReactWrapperComponent';
import {
containsChildrenSubArray,
typeOfNode,
Expand All @@ -25,9 +25,10 @@ import {
childrenOfNode,
parentsOfNode,
treeFilter,
buildPredicate,
} from './RSTTraversal';

import { buildPredicate, reduceTreeBySelector } from './selectors';

const noop = () => {};

const NODE = sym('__node__');
Expand Down Expand Up @@ -101,11 +102,6 @@ class ReactWrapper {
this.length = this[NODES].length;
}
privateSet(this, OPTIONS, root ? root[OPTIONS] : options);
privateSet(this, COMPLEX_SELECTOR, new ComplexSelector(
buildPredicate,
findWhereUnwrapped,
childrenOfNode,
));
}

/**
Expand Down Expand Up @@ -464,7 +460,7 @@ class ReactWrapper {
* @returns {ReactWrapper}
*/
find(selector) {
return this[COMPLEX_SELECTOR].find(selector, this);
return reduceTreeBySelector(selector, this);
}

/**
Expand Down
10 changes: 2 additions & 8 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import unique from 'lodash/uniq';
import compact from 'lodash/compact';
import cheerio from 'cheerio';

import ComplexSelector from './ComplexSelector';
import {
nodeEqual,
nodeMatches,
Expand All @@ -29,8 +28,8 @@ import {
childrenOfNode,
parentsOfNode,
treeFilter,
buildPredicate,
} from './RSTTraversal';
import { buildPredicate, reduceTreeBySelector } from './selectors';

const NODE = sym('__node__');
const NODES = sym('__nodes__');
Expand Down Expand Up @@ -145,11 +144,6 @@ class ShallowWrapper {
this.length = this[NODES].length;
}
privateSet(this, OPTIONS, root ? root[OPTIONS] : options);
privateSet(this, COMPLEX_SELECTOR, new ComplexSelector(
buildPredicate,
findWhereUnwrapped,
childrenOfNode,
));
}

getNodeInternal() {
Expand Down Expand Up @@ -541,7 +535,7 @@ class ShallowWrapper {
* @returns {ShallowWrapper}
*/
find(selector) {
return this[COMPLEX_SELECTOR].find(selector, this);
return reduceTreeBySelector(selector, this);
}

/**
Expand Down