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
Throw an error for complex selectors in buildPredicate
  • Loading branch information
Brandon Dail committed Sep 13, 2017
commit 5efaf08b89d4757f32e7a914cd2775ae48162727
11 changes: 10 additions & 1 deletion packages/enzyme-test-suite/test/selector-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const tests = [
},
];

describe('ComplexSelector', () => {
describe('selectors', () => {
tests.forEach(({ describeMethod, name, renderMethod }) => {
describeMethod(name, () => {
it('simple descendent', () => {
Expand Down Expand Up @@ -173,6 +173,15 @@ describe('ComplexSelector', () => {
siblings.map(sibling => expect(sibling.text()).to.not.equal('Top'));
});

it('throws for complex selectors in simple selector methods', () => {
const wrapper = renderMethod(<div className="foo" />);
['is', 'filter', 'not', 'every'].forEach((method) => {
expect(() => wrapper[method]('.foo + div')).to.throw(
`This method does not support complex CSS selectors`
);
});
});

it('.foo + div > span', () => {
const wrapper = renderMethod(
<div>
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function buildPredicate(selector) {
case 'string': {
const tokens = safelyGenerateTokens(selector);
if (isComplexSelector(tokens)) {
// @TODO throw a helpful error.
throw new TypeError('This method does not support complex CSS selectors');
}
// Simple selectors only have a single selector token
return buildPredicateFromToken(tokens[0]);
Expand Down