Added unit tests for "parser.js" and "util.js"

This commit is contained in:
euvl
2017-08-07 16:07:57 +01:00
parent 72f5222e4b
commit 0089717a8c
10 changed files with 186 additions and 7 deletions

69
test/unit/parser.spec.js Normal file
View File

@@ -0,0 +1,69 @@
var parser = require('../../src/parser')
var { expect } = require('chai')
describe('parser.js', () => {
describe('#parse', () => {
describe('Correct types', () => {
it('Should parse numbers', () => {
let object = parser.parse(10)
expect(object.value).to.be.a('number')
expect(object.type).to.be.a('string')
expect(object.value).to.equal(10)
expect(object.type).to.equal('px')
})
it('Should parse strings', () => {
let object = parser.parse('10')
expect(object.value).to.be.a('number')
expect(object.type).to.be.a('string')
expect(object.value).to.equal(10)
expect(object.type).to.equal('px')
})
it ('Should parse "auto" string, auto => {type: "auto", value: 0}', () => {
let object = parser.parse('auto')
expect(object.value).to.equal(0)
expect(object.type).to.equal('auto')
})
it ('Should parse wrong types', () => {
let nullValue = parser.parse(null)
let booleanValue = parser.parse(false)
expect(nullValue.value).to.equal(null)
expect(nullValue.type).to.equal('')
expect(booleanValue.value).to.equal(false)
expect(booleanValue.type).to.equal('')
})
})
describe('Parsing suffixed string', () => {
it ('Should parse "px"', () => {
let object = parser.parse('10px')
expect(object.value).to.equal(10)
expect(object.type).to.equal('px')
})
it ('Should parse "%"', () => {
let object = parser.parse('10%')
expect(object.value).to.equal(10)
expect(object.type).to.equal('%')
})
it ('Should not parse "%px"', () => {
let object = parser.parse('10%px')
expect(object.value).to.be.a('string')
expect(object.type).to.equal('')
})
})
})
})