@schukai/monster
Version:
Monster is a simple library for creating fast, robust and lightweight websites.
65 lines (49 loc) • 1.78 kB
JavaScript
import {expect} from 'chai';
import {extractKeys} from "../../../../source/dom/util/extract-keys.mjs";
describe('extractKeys', () => {
it('should extract keys from the given object', () => {
const obj = {
firstName: 'John',
lastName: 'Doe',
address: {
street: '123 Main St',
city: 'New York',
},
};
const expected = new Map([
['firstname', 'firstName'],
['lastname', 'lastName'],
['address-street', 'address.street'],
['address-city', 'address.city'],
]);
const result = extractKeys(obj);
expect(JSON.stringify(Array.from(result))).to.equal(JSON.stringify(Array.from(expected)));
});
it('should use custom key and value separators', () => {
const obj = {
firstName: 'John',
lastName: 'Doe',
};
const expected = new Map([
['prefix+firstname', 'prefix+firstName'],
['prefix+lastname', 'prefix+lastName'],
]);
const result = extractKeys(obj, 'prefix', '+', '+');
expect(JSON.stringify(Array.from(result))).to.equal(JSON.stringify(Array.from(expected)));
});
it('check if value is null', () => {
const obj = {
firstName: 'John',
lastName: 'Doe',
address: null,
};
const expected = new Map([
['firstname', 'firstName'],
['lastname', 'lastName'],
['address', 'address'],
]);
const result = extractKeys(obj);
expect(JSON.stringify(Array.from(result))).to.equal(JSON.stringify(Array.from(expected)));
});
// Add more test cases as needed
});