-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: organize and rename describe blocks
- Loading branch information
1 parent
b8e0e7d
commit 8d4c004
Showing
2 changed files
with
29 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict'; | ||
|
||
const invalid = [ | ||
// boolean | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,55 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const css = require('css'); | ||
const cases = require('./cases'); | ||
const parser = require('../'); | ||
const parse = require('../'); | ||
|
||
describe('parser', () => { | ||
cases.default.forEach(({ style, expected }) => { | ||
// error case | ||
describe(`when style=\`${style}\``, () => { | ||
if (expected === Error) { | ||
it('throws error', () => { | ||
assert.throws(() => parser(style), Error); | ||
assert.throws(() => parse(style), Error); | ||
}); | ||
return; | ||
} | ||
|
||
// normal case | ||
it(`returns ${JSON.stringify(expected)}`, () => { | ||
assert.deepEqual(parser(style), expected); | ||
assert.deepEqual(parse(style), expected); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when iterator is passed', () => { | ||
it('returns null', () => { | ||
const style = cases.styles[0]; | ||
const iterator = () => {}; | ||
assert.equal(parser(style, iterator), null); | ||
}); | ||
describe('iterator', () => { | ||
it('returns null', () => { | ||
const style = 'color: #foo;'; | ||
const iterator = () => {}; | ||
assert.equal(parse(style, iterator), null); | ||
}); | ||
|
||
it('passes the arguments: name, value, declaration', () => { | ||
const style = 'color: #f00;'; | ||
parser(style, (name, value, declaration) => { | ||
assert.equal(name, 'color'); | ||
assert.equal(value, '#f00'); | ||
assert.deepEqual( | ||
declaration, | ||
css.parse(`p{${style}}`).stylesheet.rules[0].declarations[0] | ||
); | ||
}); | ||
it('invokes callback with arguments=[name, value, declaration]', () => { | ||
const style = 'color: #f00;'; | ||
parse(style, (name, value, declaration) => { | ||
assert.equal(name, 'color'); | ||
assert.equal(value, '#f00'); | ||
assert.deepEqual( | ||
declaration, | ||
css.parse(`p{${style}}`).stylesheet.rules[0].declarations[0] | ||
); | ||
}); | ||
}); | ||
|
||
it('parses comment', () => { | ||
const style = '/* color: #f00; */'; | ||
parser(style, (name, value, declaration) => { | ||
assert.equal(name, undefined); | ||
assert.equal(value, undefined); | ||
assert.deepEqual( | ||
declaration, | ||
css.parse(`p{${style}}`).stylesheet.rules[0].declarations[0] | ||
); | ||
}); | ||
it('parses comment', () => { | ||
const style = '/* color: #f00; */'; | ||
parse(style, (name, value, declaration) => { | ||
assert.equal(name, undefined); | ||
assert.equal(value, undefined); | ||
assert.deepEqual( | ||
declaration, | ||
css.parse(`p{${style}}`).stylesheet.rules[0].declarations[0] | ||
); | ||
}); | ||
}); | ||
}); |