Skip to content

Commit

Permalink
fixes enzymejs#590: change isCompoundSelector to not match prop selector
Browse files Browse the repository at this point in the history
  • Loading branch information
joeduncan committed Sep 12, 2016
1 parent 69b7a18 commit 26c155b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function selectorError(selector, type = '') {
);
}

export const isCompoundSelector = /([a-z]\.[a-z]|[a-z]\[.*\]|[a-z]#[a-z])/i;
export const isCompoundSelector = /^(\w+#\w+(\.\w+)*|\.?\w+(\.\w+)+|\w+\[.*\])$/i;

const isPropSelector = /^\[.*\]$/;

Expand Down
11 changes: 11 additions & 0 deletions test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,17 @@ describe('shallow', () => {
expect(wrapper.find('.foo').type()).to.equal('input');
});

it('should find element that has dot in attribute', () => {
const wrapper = shallow(
<div>
<div data-baz="foo.bar" />
</div>
);

const elements = wrapper.find('[data-baz="foo.bar"]');
expect(elements.length).to.equal(1);
});

it('should find an element based on a tag name and class name', () => {
const wrapper = shallow(
<div>
Expand Down

4 comments on commit 26c155b

@ManuelDeLeon
Copy link

Choose a reason for hiding this comment

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

It doesn't match:

.a[b="c"]
a.b[c="d"]
a.b-c

What's wrong with /^[\.#]?-?[_a-z]+[_a-z0-9-]*[\.\[#]/i?

I acknowledge that it can return true for a malformed selector but is it any worse than the alternative: for the regex test to say "I've parsed this (malformed) selector and I can tell you it is not compound." They're both wrong so we might as well go with the simpler one.

@joeduncan
Copy link
Owner Author

Choose a reason for hiding this comment

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

true

@joeduncan
Copy link
Owner Author

Choose a reason for hiding this comment

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

I changed it and added more test cases

@ManuelDeLeon
Copy link

Choose a reason for hiding this comment

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

You smell that? It's the sweet smell of a painless contribution.

Other projects require you to sacrifice a chicken and a goat for them to fix anything.

Thanks.

Please sign in to comment.