Skip to content

Commit

Permalink
fixes #590: change isCompoundSelector to not match prop selector
Browse files Browse the repository at this point in the history
  • Loading branch information
joeduncan committed Oct 12, 2016
1 parent 58764f1 commit c012371
Show file tree
Hide file tree
Showing 2 changed files with 45 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 @@ -195,7 +195,7 @@ export function selectorError(selector, type = '') {
);
}

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

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

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

it('should find an 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 that with class and attribute', () => {
const wrapper = shallow(
<div>
<div data-baz="bar" className="classBar" />
</div>
);

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

it('should find an element that with multiple classes and one attribute', () => {
const wrapper = shallow(
<div>
<div data-baz="bar" className="classBar classFoo" />
</div>
);

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

it('should find an element that with class and class with hyphen', () => {
const wrapper = shallow(
<div>
<div data-baz="bar" className="classBar class-Foo" />
</div>
);

const elements = wrapper.find('.classBar.class-Foo');
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

0 comments on commit c012371

Please sign in to comment.