|
| 1 | +var test = require('tape') |
| 2 | +var concat = require('simple-concat') |
| 3 | +var hyperstream = require('../') |
| 4 | + |
| 5 | +test('complex attribute selector', function (t) { |
| 6 | + var hs = hyperstream({ |
| 7 | + 'div[class^="it"][class$="work"]': { class: 'it worked' } |
| 8 | + }) |
| 9 | + concat(hs, function (err, result) { |
| 10 | + t.ifError(err) |
| 11 | + t.equal(result + '', '<div id="a"><div class="it worked"></div></div>') |
| 12 | + t.end() |
| 13 | + }) |
| 14 | + hs.end('<div id="a"><div class="it should work"></div></div>') |
| 15 | +}) |
| 16 | + |
| 17 | +test('attributes w/ newlines', function (t) { |
| 18 | + var hs = hyperstream({ |
| 19 | + '#a': { class: 'it worked' } |
| 20 | + }) |
| 21 | + concat(hs, function (err, result) { |
| 22 | + t.ifError(err) |
| 23 | + t.equal(result + '', '<div class="it worked" id="a"></div>') |
| 24 | + t.end() |
| 25 | + }) |
| 26 | + hs.end(`<div class="it |
| 27 | + should work" |
| 28 | + id="a"></div>`) |
| 29 | +}) |
| 30 | + |
| 31 | +test('match multiple classes', function (t) { |
| 32 | + var hs = hyperstream({ |
| 33 | + '.first.second': { class: 'first second third' } |
| 34 | + }) |
| 35 | + concat(hs, function (err, result) { |
| 36 | + t.ifError(err) |
| 37 | + t.equal(result + '', '<div class="first second third"></div>') |
| 38 | + t.end() |
| 39 | + }) |
| 40 | + hs.end('<div class="first second"></div>') |
| 41 | +}) |
| 42 | + |
| 43 | +test('match single class against several', function (t) { |
| 44 | + var hs = hyperstream({ |
| 45 | + '.second': { class: 'first second third' } |
| 46 | + }) |
| 47 | + concat(hs, function (err, result) { |
| 48 | + t.ifError(err) |
| 49 | + t.equal(result + '', '<div class="first second third"></div>') |
| 50 | + t.end() |
| 51 | + }) |
| 52 | + hs.end('<div class="first second"></div>') |
| 53 | +}) |
| 54 | + |
| 55 | +test('match mixed attributes', function (t) { |
| 56 | + var hs = hyperstream({ |
| 57 | + 'div#a.b[c="d"]': { _prependHtml: 'matched' } |
| 58 | + }) |
| 59 | + concat(hs, function (err, result) { |
| 60 | + t.ifError(err) |
| 61 | + t.equal(result + '', '<div id="a" class="b" c="d">matched</div>') |
| 62 | + t.end() |
| 63 | + }) |
| 64 | + hs.end('<div id="a" class="b" c="d"></div>') |
| 65 | +}) |
0 commit comments