Skip to content

Commit

Permalink
Create enumerable properties for properties.path()
Browse files Browse the repository at this point in the history
The return value of properties.path() had enumerable keys in 2.1.1 and
earlier. Starting in 2.2.0, the keys were no longer enumerable as part
of the change made for steveukx#40 in 0877cc8.

Fixes steveukx#58
  • Loading branch information
ms1111 committed Jan 13, 2024
1 parent c1bd0b4 commit 3e8d798
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/properties-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ PropertiesReader.prototype.set = function (key, value) {
}

if (!has(source, step)) {
Object.defineProperty(source, step, { value: {} });
Object.defineProperty(source, step, { value: {}, enumerable: true });
}

source = source[step]
}

if (expanded[0] === '__proto__') {
Object.defineProperty(source, expanded[0], { value: parsedValue });
Object.defineProperty(source, expanded[0], { value: parsedValue, enumerable: true });
}
else if (typeof parsedValue === 'string' && typeof source[expanded[0]] === 'object') {
source[expanded[0]][''] = parsedValue;
Expand Down
7 changes: 7 additions & 0 deletions test/reader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ describe('Reader', () => {
expect(properties.path().foo.bar).toBe('A Value');
});

it('Property paths are enumerable', async () => {
await givenTheProperties('some.property=Value');

expect(Object.keys(properties.path())).toEqual(['some']);
expect(Object.keys(properties.path().some)).toEqual(['property']);
});

it('Sets properties into an app', async () => {
const set = jest.fn();
(await givenTheProperties(`
Expand Down

0 comments on commit 3e8d798

Please # to comment.