wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
126 lines • 4.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var flatten_1 = require("./flatten");
describe('flatten', function () {
describe('given array of non-nested objects', function () {
it('should return same shape array', function () {
var assertion = [
{ a: 1, type: 'unknown' },
{ b: 2, type: 'unknown' },
];
expect((0, flatten_1.flatten)(assertion)).toEqual(assertion);
});
});
describe('given array of objects with type `object`', function () {
it('should flatten `props` array', function () {
var assertion = [
{ a: 1, type: 'unknown' },
{
type: 'object',
props: [{ b: 2, type: 'unknown' }],
},
];
var expectation = [
{ a: 1, type: 'unknown' },
{ b: 2, type: 'unknown' },
];
expect((0, flatten_1.flatten)(assertion)).toEqual(expectation);
});
it('should concat `name` and key of nested `props` with dot', function () {
var assertion = [
{
a: 1,
type: 'unknown',
name: 'first',
},
{
name: 'second',
type: 'object',
props: [
{
name: 'nested',
type: 'unknown',
b: 2,
},
],
},
];
var expectation = [
{ a: 1, type: 'unknown', name: 'first' },
{ b: 2, type: 'unknown', name: 'second.nested' },
];
expect((0, flatten_1.flatten)(assertion)).toEqual(expectation);
});
it('should work with deeply nested objects', function () {
var assertion = [
{
a: 1,
type: 'unknown',
name: 'first',
},
{
name: 'second',
type: 'object',
props: [
{
name: 'nested',
type: 'unknown',
b: 2,
},
{
type: 'object',
name: 'third',
props: [
{
name: 'wheel',
type: 'unknown',
c: 3,
},
],
},
{
name: 'sibling',
type: 'unknown',
d: 4,
},
],
},
];
var expectation = [
{ a: 1, type: 'unknown', name: 'first' },
{ b: 2, type: 'unknown', name: 'second.nested' },
{ c: 3, type: 'unknown', name: 'second.third.wheel' },
{ d: 4, type: 'unknown', name: 'second.sibling' },
];
expect((0, flatten_1.flatten)(assertion)).toEqual(expectation);
});
});
describe('given array of erroneous', function () {
it('should skip them and work with non erroneous', function () {
var assertion = [
{
a: 1,
type: 'unknown',
name: 'first',
},
null,
[],
0,
false,
{
b: 2,
type: 'unknown',
name: 'second',
},
];
var expectation = [
{ a: 1, type: 'unknown', name: 'first' },
{ b: 2, type: 'unknown', name: 'second' },
];
// intentional ignore, JS consumer might pass falsy input
// @ts-ignore
expect((0, flatten_1.flatten)(assertion)).toEqual(expectation);
});
});
});
//# sourceMappingURL=flatten.test.js.map