Skip to content

[WIP] Add unit tests #42

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions __mocks__/uuid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
v4: function () {
return 'xxxx-xxxx'
}
}
71 changes: 71 additions & 0 deletions __tests__/transpiler.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var superviews = require('../index')

function addWrapper (content) {
return ';(function () {' + '\n' + content + '\n' + '})()' + '\n'
}

describe('template', function () {
describe('with static content', function () {
it('should transpile simple element', function () {
var expected = (
`var __target

return function description (data) {
elementOpen("div")
elementClose("div")
}`)
var output = superviews('<div></div>')
expect(output).toEqual(addWrapper(expected))
})

it('should transpile simple element with attributes', function () {
var expected = (
`var hoisted1 = ["class", "header", "id", "title"]
var __target

return function description (data) {
elementOpen("h1", "xxxx-xxxx", hoisted1)
elementClose("h1")
}`)

var output = superviews('<h1 class="header" id="title"></h1>')
expect(output).toEqual(addWrapper(expected))
})

it('should transpile void element', function () {
var expected = (
`var __target

return function description (data) {
elementOpen("br")
elementClose("br")
}`)
var output = superviews('<br/>')
expect(output).toEqual(addWrapper(expected))
})

it('should transpile single line text', function () {
var expected = (
`var __target

return function description (data) {
text("my text")
}`)
var output = superviews('my text')
expect(output).toEqual(addWrapper(expected))
})

it('should transpile multi line text', function () {
var expected = (
`var __target

return function description (data) {
text("my very \\
long \\
text")
}`)
var output = superviews('my very \n long \n text')
expect(output).toEqual(addWrapper(expected))
})
})
})
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"build:playground": "browserify -d examples/playground/playground.js > examples/playground/playground.bundle.js",
"build:customelements": "browserify examples/client/x-todos/index.js -t [superviewify --args 'el state'] -d -o examples/client/x-todos/bundle.js",
"build:examples": "browserify examples/client/x-widget/index.js -t [superviewify --args 'el state ctrl'] -d -o examples/client/x-widget/bundle.js",
"build:readme": "cat test/readme.html | ./bin/cmd.js > test/readme.js"
"build:readme": "cat test/readme.html | ./bin/cmd.js > test/readme.js",
"test": "jest",
"test:watch": "jest --watch"
},
"repository": {
"type": "git",
Expand All @@ -34,6 +36,7 @@
"devDependencies": {
"brace": "0.9.0",
"browserify": "13.1.1",
"jest": "^20.0.4",
"standard": "8.5.0",
"superviewify": "3.0.0"
},
Expand Down