Skip to content

Commit

Permalink
Add stringify tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeti-or committed Jun 3, 2017
1 parent 0911d15 commit f5e1bf4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -80,7 +80,7 @@ function stringify(bemjson, ctx, opts) {
opts || (opts = {});
opts.indent || (opts.indent = ' ');

return stringifyObj(getEntities(bemjson, ctx), opts);
return stringifyObj(getEntities(bemjson, ctx).map(entity => entity.toJSON()), opts);
}

module.exports = {
Expand Down
73 changes: 73 additions & 0 deletions tests/stringify.js
@@ -0,0 +1,73 @@
const expect = require('chai').expect;
const stringify = require('..').stringify;

it('should stringify simple bemjson', () => {
expect(stringify({ block: 'button2' })).to.equal(
`[
{
block: 'button2'
}
]`);

});

it('should stringify bemjson with several entities', () => {
expect(stringify({
block: 'button2',
content: [
{ block: 'icon', mods: { type: 'left' }},
{ block: 'icon', mods: { type: 'right' }}
]})).to.equal(
`[
{
block: 'button2'
},
{
block: 'icon'
},
{
block: 'icon',
mod: {
name: 'type',
val: true
}
},
{
block: 'icon',
mod: {
name: 'type',
val: 'left'
}
},
{
block: 'icon',
mod: {
name: 'type',
val: 'right'
}
}
]`);

});

it('should stringify bemjson with ctx', () => {
expect(stringify({ elem: 'text' }, { block: 'button2' })).to.equal(
`[
{
block: 'button2',
elem: 'text'
}
]`);

});

it('should stringify bemjson with stringify opts', () => {
expect(stringify({ block: 'button2', elem: 'text' }, null, { indent: ' ' })).to.equal(
`[
{
block: 'button2',
elem: 'text'
}
]`);

});

0 comments on commit f5e1bf4

Please sign in to comment.