diff --git a/src/Utils.js b/src/Utils.js index 5187321c3..01537569e 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -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 = /^\[.*\]$/; diff --git a/test/ShallowWrapper-spec.jsx b/test/ShallowWrapper-spec.jsx index a8769fba0..4c53ee87c 100644 --- a/test/ShallowWrapper-spec.jsx +++ b/test/ShallowWrapper-spec.jsx @@ -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( +
+
+
+ ); + + 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( +
+
+
+ ); + + 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( +
+
+
+ ); + + 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( +
+
+
+ ); + + 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(