Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test existing attribute selectors (CSS2)

  • Loading branch information...
commit a6bcaa5c786ad8c2b02167c5c144abc59d95e0f0 1 parent b1d512d
@Maff- Maff- authored committed
Showing with 55 additions and 0 deletions.
  1. +6 −0 test/attribute_selectors.html
  2. +49 −0 test/attribute_selectors.js
View
6 test/attribute_selectors.html
@@ -0,0 +1,6 @@
+<ul class="list-attributes">
+ <li class="item1 item-first" data-role="item-first">item1</li>
+ <li class="item2" data-foo="somerandomstring" data-role="seconditem">item2</li>
+ <li class="item3" data-role="item">item3</li>
+ <li class="item4 item-last" data-role="item-last">item4</li>
+</ul>
View
49 test/attribute_selectors.js
@@ -0,0 +1,49 @@
+var trumpet = require('../');
+var fs = require('fs');
+var test = require('tape');
+var concat = require('concat-stream');
+
+test('selected element has attribute [att]', function (t) {
+ t.plan(1);
+
+ var tr = trumpet();
+ tr.createReadStream('li[data-foo]').pipe(concat(function (elem) {
+ t.equal(elem.toString(), 'item2');
+ }));
+ fs.createReadStream(__dirname + '/attribute_selectors.html').pipe(tr);
+});
+
+test('selected element has attribute value [att=val]', function (t) {
+ t.plan(1);
+
+ var tr = trumpet();
+ tr.createReadStream('li[class="item1 item-first"]').pipe(concat(function (elem) {
+ t.equal(elem.toString(), 'item1');
+ }));
+ fs.createReadStream(__dirname + '/attribute_selectors.html').pipe(tr);
+});
+
+test('selected element contains whitespace seperated attribute value [att~=val]', function (t) {
+ t.plan(1);
+
+ var tr = trumpet();
+ tr.createReadStream('li[class~=item-first]').pipe(concat(function (elem) {
+ t.equal(elem.toString(), 'item1');
+ }));
+ fs.createReadStream(__dirname + '/attribute_selectors.html').pipe(tr);
+});
+
+test('selected element attribute value equals or starts with and followed by - [att|=val]', function (t) {
+
+ var items = ['item1', 'item3', 'item4'];
+ t.plan(items.length);
+
+ var tr = trumpet();
+ tr.selectAll('li[data-role|=item]', function (elem) {
+ elem.createReadStream().pipe(concat(function (src) {
+ t.equal(src.toString(), items.shift());
+ }));
+ });
+
+ fs.createReadStream(__dirname + '/attribute_selectors.html').pipe(tr);
+});
Please sign in to comment.
Something went wrong with that request. Please try again.