BE-SPAN/node_modules/dottie/test/flatten.test.js

40 lines
708 B
JavaScript
Raw Normal View History

2024-10-20 15:04:16 +00:00
var expect = require("expect.js"),
dottie = require('../dottie');
describe("dottie.flatten", function () {
it('should handle a basic nested structure without arrays', function () {
var data = {
'foo': {
'bar': 'baa',
'baz': {
'foo': 'bar'
}
},
'bar': 'baz'
};
expect(dottie.flatten(data)).to.eql({
'foo.bar': 'baa',
'foo.baz.foo': 'bar',
'bar': 'baz'
});
});
it('should be possible to define your own seperator', function () {
var data = {
'foo': {
'bar': 'baa',
'baz': {
'foo': 'bar'
}
},
'bar': 'baz'
};
expect(dottie.flatten(data, '_')).to.eql({
'foo_bar': 'baa',
'foo_baz_foo': 'bar',
'bar': 'baz'
});
});
});