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

Id selector not working when combined with a tag selector (#314) #387

Merged
merged 1 commit into from
May 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function withSetStateAllowed(fn) {
}

export function splitSelector(selector) {
return selector.split(/(?=\.|\[.*\])/);
return selector.split(/(?=\.|\[.*\])|(?=#|\[#.*\])/);
}

export function isSimpleSelector(selector) {
Expand All @@ -176,7 +176,7 @@ export function selectorError(selector) {
);
}

export const isCompoundSelector = /([a-z]\.[a-z]|[a-z]\[.*\])/i;
export const isCompoundSelector = /([a-z]\.[a-z]|[a-z]\[.*\]|[a-z]#[a-z])/i;

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

Expand Down
27 changes: 27 additions & 0 deletions test/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,33 @@ describeWithDOM('mount', () => {
expect(wrapper.find('input').props().className).to.equal('foo');
});

it('should find an element based on a tag name and class name', () => {
const wrapper = mount(
<div>
<input className="foo" />
</div>
);
expect(wrapper.find('input.foo').length).to.equal(1);
});

it('should find an element based on a tag name and id', () => {
const wrapper = mount(
<div>
<input id="foo" />
</div>
);
expect(wrapper.find('input#foo').length).to.equal(1);
});

it('should find an element based on a tag name, id, and class name', () => {
const wrapper = mount(
<div>
<input id="foo" className="bar" />
</div>
);
expect(wrapper.find('input#foo.bar').length).to.equal(1);
});

it('should find a component based on a constructor', () => {
class Foo extends React.Component {
render() { return <div />; }
Expand Down
27 changes: 27 additions & 0 deletions test/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,33 @@ describe('shallow', () => {
expect(wrapper.find('.foo').type()).to.equal('input');
});

it('should find an element based on a tag name and class name', () => {
const wrapper = shallow(
<div>
<input className="foo" />
</div>
);
expect(wrapper.find('input.foo').length).to.equal(1);
});

it('should find an element based on a tag name and id', () => {
const wrapper = shallow(
<div>
<input id="foo" />
</div>
);
expect(wrapper.find('input#foo').length).to.equal(1);
});

it('should find an element based on a tag name, id, and class name', () => {
const wrapper = shallow(
<div>
<input id="foo" className="bar" />
</div>
);
expect(wrapper.find('input#foo.bar').length).to.equal(1);
});

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