Skip to content

Commit

Permalink
Add tests for matching invalid attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jordwest committed May 25, 2016
1 parent da2ef13 commit a293636
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function buildInstPredicate(selector) {
case SELECTOR.ID_TYPE:
return inst => instHasId(inst, selector.substr(1));
case SELECTOR.PROP_TYPE: {
const propKey = selector.split(/\[([a-zA-Z\d\-\:]*?)(=|\])/)[1];
const propKey = selector.split(/\[([a-zA-Z][a-zA-Z\d\-\:]*?)(=|\])/)[1];
const propValue = selector.split(/=(.*?)]/)[1];

return node => instHasProperty(node, propKey, propValue);
Expand Down
22 changes: 20 additions & 2 deletions test/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,34 @@ describeWithDOM('mount', () => {

});

it('should not find components with invalid attributes', () => {
// Invalid attributes aren't valid JSX, so manual instantiation is necessary
const wrapper = mount(
React.createElement('div', null, React.createElement('span', {
'123-foo': 'bar',
'-foo': 'bar',
':foo': 'bar',
}))
);

expect(wrapper.find('[-foo]')).to.have.length(0, '-foo');
expect(wrapper.find('[:foo]')).to.have.length(0, ':foo');
expect(wrapper.find('[123-foo]')).to.have.length(0, '123-foo');
});

it('should support data prop selectors', () => {
const wrapper = mount(
<div>
<span data-foo="bar" data-foo123="bar" />
<span data-foo="bar" />
<span data-foo-123="bar2" />
<span data-123-foo="bar3" />
</div>
);

expect(wrapper.find('[data-foo="bar"]')).to.have.length(1);
expect(wrapper.find('[data-foo]')).to.have.length(1);
expect(wrapper.find('[data-foo123]')).to.have.length(1);
expect(wrapper.find('[data-foo-123]')).to.have.length(1);
expect(wrapper.find('[data-123-foo]')).to.have.length(1);
});

it('should find components with multiple matching props', () => {
Expand Down

0 comments on commit a293636

Please sign in to comment.