Skip to content

Commit

Permalink
Merge f622256 into c1c847d
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed May 23, 2021
2 parents c1c847d + f622256 commit 2862ba7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/util/storage.js
Expand Up @@ -237,6 +237,7 @@ class Storage {
/**
* Create a child storage.
* @param {String} path - relative path of the key to create a new storage.
* Some paths need to be escaped. Eg: ["dotted.path"]
* @return {Storage} Returns a new Storage.
*/
createStorage(path) {
Expand Down
38 changes: 29 additions & 9 deletions test/storage.js
Expand Up @@ -324,17 +324,37 @@ describe('Storage', () => {
});

describe('#getStorage()', () => {
beforeEach(function () {
this.pathStore = this.store.createStorage('path');
describe('with a path safe string', () => {
beforeEach(function () {
this.pathStore = this.store.createStorage('path');
});

it('should get and set value', function () {
assert.equal(this.pathStore.setPath('name', 'initial'), 'initial');
assert.equal(this.store.get('path').name, 'initial');
assert.equal(this.store.getPath('path').name, 'initial');
this.store.set('path', {name: 'test'});
assert.equal(this.pathStore.get('name'), 'test');
this.pathStore.set('name', 'changed');
assert.equal(this.store.get('path').name, 'changed');
});
});
describe('with a path unsafe string', () => {
const keyName = 'path.key';

it('get and set value', function () {
assert.equal(this.pathStore.setPath('name', 'initial'), 'initial');
assert.equal(this.store.get('path').name, 'initial');
this.store.set('path', {name: 'test'});
assert.equal(this.pathStore.get('name'), 'test');
this.pathStore.set('name', 'changed');
assert.equal(this.store.get('path').name, 'changed');
beforeEach(function () {
this.pathStore = this.store.createStorage(`["${keyName}"]`);
});

it('should get and set value', function () {
assert.equal(this.pathStore.setPath('name', 'initial'), 'initial');
assert.equal(this.store.get(keyName).name, 'initial');
assert.equal(this.store.getPath(`["${keyName}"]`).name, 'initial');
this.store.set(keyName, {name: 'test'});
assert.equal(this.pathStore.get('name'), 'test');
this.pathStore.set('name', 'changed');
assert.equal(this.store.get(keyName).name, 'changed');
});
});
});

Expand Down

0 comments on commit 2862ba7

Please sign in to comment.