File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ class Html5LibDomAdapter implements DomAdapter {
1313 hasProperty (element, String name) {
1414 // This is needed for serverside compile to generate the right getters/setters.
1515 // TODO: change this once we have property schema support.
16- // Attention: Keep this in sync with browser_adapter.dart!
16+ // Attention: Keep this in sync with browser_adapter.dart!
1717 return true ;
1818 }
1919
@@ -235,10 +235,14 @@ class Html5LibDomAdapter implements DomAdapter {
235235 return map;
236236 }
237237 hasAttribute (element, String attribute) {
238- throw 'not implemented' ;
238+ // `attributes` keys can be {@link AttributeName}s.
239+ return element.attributes.keys.any ((key) => '$key ' == attribute);
239240 }
240241 getAttribute (element, String attribute) {
241- throw 'not implemented' ;
242+ // `attributes` keys can be {@link AttributeName}s.
243+ var key = element.attributes.keys.firstWhere (
244+ (key) => '$key ' == attribute, orElse: () {});
245+ return element.attributes[key];
242246 }
243247 setAttribute (element, String name, String value) {
244248 element.attributes[name] = value;
Original file line number Diff line number Diff line change @@ -16,5 +16,19 @@ main() {
1616 it ('should parse HTML' , () {
1717 expect (subject.parse ('<div>hi</div>' ), isNotNull);
1818 });
19+
20+ it ('implements hasAttribute' , () {
21+ var div = subject.querySelector (
22+ subject.parse ('<div foo="bar"></div>' ), ('div' ));
23+ expect (subject.hasAttribute (div, 'foo' )).toBeTrue ();
24+ expect (subject.hasAttribute (div, 'bar' )).toBeFalse ();
25+ });
26+
27+ it ('implements getAttribute' , () {
28+ var div = subject.querySelector (
29+ subject.parse ('<div foo="bar"></div>' ), ('div' ));
30+ expect (subject.getAttribute (div, 'foo' )).toEqual ('bar' );
31+ expect (subject.getAttribute (div, 'bar' )).toBe (null );
32+ });
1933 });
2034}
You can’t perform that action at this time.
0 commit comments