-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple space-separated values within a single element's dat…
…a-test-subj attribute (#1587) * Add matcher argument to findTestSubject. * Add tests.
- Loading branch information
Showing
3 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { findTestSubject } from './find_test_subject'; | ||
|
||
describe('findTestSubject', () => { | ||
test('finds the specified element in a mounted component', () => { | ||
const TestComponent = () => <div data-test-subj="test" />; | ||
const component = mount(<TestComponent />); | ||
const element = findTestSubject(component, 'test'); | ||
|
||
expect(element.length).toBe(1); | ||
}); | ||
|
||
test('finds the specified element even if it has multiple identifiers', () => { | ||
const TestComponent = () => <div data-test-subj="test1 test2" />; | ||
const component = mount(<TestComponent />); | ||
const element = findTestSubject(component, 'test2'); | ||
|
||
expect(element.length).toBe(1); | ||
}); | ||
|
||
test('finds multiple elements with the same identifier', () => { | ||
const TestComponent = () => ( | ||
<div> | ||
<div data-test-subj="test" /> | ||
<div data-test-subj="test" /> | ||
</div> | ||
); | ||
const component = mount(<TestComponent />); | ||
const element = findTestSubject(component, 'test'); | ||
|
||
expect(element.length).toBe(2); | ||
}); | ||
|
||
describe('matcher optional argument', () => { | ||
test('finds multiple elements with identifiers beginning with the same string', () => { | ||
const TestComponent = () => ( | ||
<div> | ||
<div data-test-subj="test1" /> | ||
<div data-test-subj="test2" /> | ||
</div> | ||
); | ||
const component = mount(<TestComponent />); | ||
const element = findTestSubject(component, 'test', '^='); | ||
|
||
expect(element.length).toBe(2); | ||
}); | ||
|
||
test('throws an error if unsupported matcher is provided', () => { | ||
const TestComponent = () => <div data-test-subj="test" />; | ||
const component = mount(<TestComponent />); | ||
expect(() => findTestSubject(component, 'test', '===')).toThrow(); | ||
}); | ||
}); | ||
}); |