Skip to content

Commit

Permalink
rewrite values tests (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Mar 3, 2019
1 parent 94d1ce8 commit babcef7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/analyzer/values/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = declarations => {
const all = declarations.map(declaration => declaration.value)
const all = declarations.map(({value}) => value)

const prefixed = require('./prefixed.js')(all)
const fontsizes = require('./font-sizes.js')(declarations)
Expand Down
50 changes: 45 additions & 5 deletions test/analyzer/values/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
const test = require('ava')
const testScope = require('../../utils/scope-tester.js')
const analyze = require('../../../src/analyzer/values')

const SCOPE = 'values'
test('It responds with the correct structure', t => {
const {
total,
boxshadows,
browserhacks,
colors,
fontfamilies,
fontsizes,
prefixed,
zindexes
} = analyze([{property: 'a', value: '0'}])

test(SCOPE, async t => {
const {actual, expected} = await testScope(SCOPE)
t.deepEqual(actual[SCOPE], expected)
t.is(total, 1)
t.truthy(boxshadows)
t.truthy(browserhacks)
t.truthy(colors)
t.truthy(fontfamilies)
t.truthy(fontsizes)
t.truthy(prefixed)
t.truthy(zindexes)
})

test('It analyzes values with comments', t => {
t.is(analyze([{property: 'a', value: 'a/* comment */'}]).total, 1)
})

test('It analyzes values with custom properties', t => {
const fixture = [{property: 'height', value: 'var(--my-custom-property)'}]
t.notThrows(() => analyze(fixture))
t.is(analyze(fixture).total, 1)
})

test('It analyzes complex values', t => {
const fixtures = [
{property: 'grid-column', value: '1/-1'},
{property: 'grid-column', value: '1 /-1'},
{property: 'grid-column', value: '1/ -1'},
{property: 'grid-column', value: '1 / -1'},
{property: 'width', value: 'calc(100px + 2%)'}
]

fixtures.forEach(fixture => {
t.notThrows(() => analyze([fixture]))
t.is(analyze([fixture]).total, 1)
})
})
30 changes: 0 additions & 30 deletions test/analyzer/values/input.css

This file was deleted.

49 changes: 0 additions & 49 deletions test/analyzer/values/output.json

This file was deleted.

0 comments on commit babcef7

Please sign in to comment.