mirror of
https://github.com/KevinMidboe/vue-js-modal.git
synced 2025-12-29 05:11:26 +00:00
Added unit tests for "parser.js" and "util.js"
This commit is contained in:
69
test/unit/parser.spec.js
Normal file
69
test/unit/parser.spec.js
Normal 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('')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user