From c012371741d54a3f845faffc59cde4bc86d21020 Mon Sep 17 00:00:00 2001 From: Joseph Duncan Date: Mon, 12 Sep 2016 18:10:17 +0200 Subject: [PATCH] fixes #590: change isCompoundSelector to not match prop selector --- src/Utils.js | 2 +- test/ShallowWrapper-spec.jsx | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) 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 c6b1be8ba..02a7e9639 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(