Skip to content

Commit

Permalink
create attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
bredele committed Aug 19, 2016
1 parent c49faf7 commit ec67533
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = function(arr, ...args) {
if(match) {
str = str.substring(match[0].length)
node = node.appendChild(document.createElement(match[1]))
var attrs = match[2]
match[2].replace(attr, function(_, key, value) {
node.setAttribute(key, value)
})
Expand Down
47 changes: 26 additions & 21 deletions test/vomit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@
var tape = require('tape')
var vomit = require('..')

// simple element
// tape('should create element', (test) => {
// test.plan(1)
// var btn = vomit`<button>hello</button>`
// test.equal(btn.outerHTML, '<button>hello</button>')
// })
//
// tape('should interpolate string', (test) => {
// test.plan(1)
// var label = 'hello'
// var btn = vomit`<button>${label}</button>`
// test.equal(btn.outerHTML, '<button>hello</button>')
// })
//
// tape('should create multiple elements', (test) => {
// test.plan(1)
// var label = 'hello'
// var section = vomit`<section><button>${label}</button></section>`
// test.equal(section.outerHTML, '<section><button>hello</button></section>')
// })
tape('should create element', (test) => {
test.plan(1)
var btn = vomit`<button>hello</button>`
test.equal(btn.outerHTML, '<button>hello</button>')
})

tape('should interpolate string', (test) => {
test.plan(1)
var label = 'hello'
var btn = vomit`<button>${label}</button>`
test.equal(btn.outerHTML, '<button>hello</button>')
})

tape('should create multiple elements', (test) => {
test.plan(1)
var label = 'hello'
var section = vomit`<section><button>${label}</button></section>`
test.equal(section.outerHTML, '<section><button>hello</button></section>')
})


// element with attributes
tape('should create element with attributes', (test) => {
test.plan(1)
var btn = vomit`<button id="btn" class="test">hello</button>`
test.equal(btn.outerHTML, '<button id="btn" class="test">hello</button>')
})

// tape('should interpolate attributes', (test) => {
// test.plan(1)
// var name = 'olivier'
// var btn = vomit`<button id="${name}" class="${name}">hello</button>`
// test.equal(btn.outerHTML, '<button id="${name}" class="${name}">hello</button>')
// })

0 comments on commit ec67533

Please sign in to comment.