-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: Allow specifying preferred attributes #7
Conversation
it( 'data-foo', () => | ||
{ | ||
$( 'body' ).get( 0 ).innerHTML = ''; // Clear previous appends | ||
$( 'body' ).append( '<div data-foo="so" class="test6"></div>' ); | ||
const findNode = $( 'body' ).find( '.test6' ).get( 0 ); | ||
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } ); | ||
expect( uniqueSelector ).to.equal( '[data-foo="so"]' ); | ||
} ); | ||
describe('data attribute', () => { | ||
it( 'data-foo', () => | ||
{ | ||
$( 'body' ).get( 0 ).innerHTML = ''; // Clear previous appends | ||
$( 'body' ).append( '<div data-foo="so" class="test6"></div>' ); | ||
const findNode = $( 'body' ).find( '.test6' ).get( 0 ); | ||
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } ); | ||
expect( uniqueSelector ).to.equal( '[data-foo="so"]' ); | ||
} ); | ||
|
||
it( 'data-foo-bar-baz', () => | ||
{ | ||
$( 'body' ).get( 0 ).innerHTML = ''; // Clear previous appends | ||
$( 'body' ).append( '<div data-foo-bar-baz="so" class="test6"></div>' ); | ||
const findNode = $( 'body' ).find( '.test6' ).get( 0 ); | ||
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo-bar-baz'] } ); | ||
expect( uniqueSelector ).to.equal( '[data-foo-bar-baz="so"]' ); | ||
} ); | ||
it( 'data-foo-bar-baz', () => | ||
{ | ||
$( 'body' ).get( 0 ).innerHTML = ''; // Clear previous appends | ||
$( 'body' ).append( '<div data-foo-bar-baz="so" class="test6"></div>' ); | ||
const findNode = $( 'body' ).find( '.test6' ).get( 0 ); | ||
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo-bar-baz'] } ); | ||
expect( uniqueSelector ).to.equal( '[data-foo-bar-baz="so"]' ); | ||
} ); | ||
|
||
it( 'data-foo-bar with quotes', () => | ||
{ | ||
$( 'body' ).get( 0 ).innerHTML = ''; // Clear previous appends | ||
$( 'body' ).append( '<div data-foo-bar="button 123" class="test7"></div>' ); | ||
const findNode = $( 'body' ).find( '.test7' ).get( 0 ); | ||
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo-bar'] } ); | ||
expect( uniqueSelector ).to.equal( '[data-foo-bar="button 123"]' ); | ||
} ); | ||
it( 'data-foo-bar with quotes', () => | ||
{ | ||
$( 'body' ).get( 0 ).innerHTML = ''; // Clear previous appends | ||
$( 'body' ).append( '<div data-foo-bar="button 123" class="test7"></div>' ); | ||
const findNode = $( 'body' ).find( '.test7' ).get( 0 ); | ||
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo-bar'] } ); | ||
expect( uniqueSelector ).to.equal( '[data-foo-bar="button 123"]' ); | ||
} ); | ||
|
||
it( 'data-foo without value', () => | ||
{ | ||
$( 'body' ).get( 0 ).innerHTML = ''; // Clear previous appends | ||
$( 'body' ).append( '<div data-foo class="test7"></div>' ); | ||
const findNode = $( 'body' ).find( '.test7' ).get( 0 ); | ||
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } ); | ||
expect( uniqueSelector ).to.equal( '[data-foo]' ); | ||
} ); | ||
it( 'data-foo without value', () => | ||
{ | ||
$( 'body' ).get( 0 ).innerHTML = ''; // Clear previous appends | ||
$( 'body' ).append( '<div data-foo class="test7"></div>' ); | ||
const findNode = $( 'body' ).find( '.test7' ).get( 0 ); | ||
const uniqueSelector = unique( findNode, { selectorTypes : ['data-foo'] } ); | ||
expect( uniqueSelector ).to.equal( '[data-foo]' ); | ||
} ); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only change here was nesting under a new describe
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the difference between this and data attributes is that the data-
part is included in the attribute on the html element. So data-foo
relates to <div data-foo>
while attribute-foo
relates to <div foo>
. For that reason, I think it might make sense to differentiate them. What about having it be attribute:foo
, attribute:foo-bar
, etc. instead?
@chrisbreiding Fabulous idea. I love it. Change made in 91a41d4 |
🎉 This PR is included in version 1.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This enables providing a set of preferred attributes to use when building selectors - this is different from the existing
attributes
selector type which builds a selector using any permutation of attributes. The impetus of this change is in UI Coverage there are cases where we want to leverage specific vendor/custom attributes which are significant but are notdata-*
attributes - these are technically invalid per the HTML spec but are widely used regardless. Specifically, the AG Grid library uses arow-id
attribute that we want to leverage whenever possible since it helps form a stable identifier when there are auto-generatedid
values.This follows a similar pattern to the existing
data-*
attribute handling. You can supply aattribute-*
selectorType which will be evaluated exactly the same after strippingattribute-
off the front. e.g.attribute-role
would use therole
attribute,attribute-more-cowbell
would usemore-cowbell
.Technically this pattern could replace the dedicated
data-*
path by providing a value ofattribute-data-cy
, but in the interests of making this a non-breaking change I've left that path intact