Skip to content

Commit

Permalink
feat: add 'has' method in bag class
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcachi committed Jun 13, 2023
1 parent 3bd3405 commit 18353fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/__tests__/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,32 @@ test('constructor', () => {
customParam: [new Test()]
});

klient.parameters.merge({
const { parameters } = klient;

parameters.merge({
name: 'KlientTest',
customParam: [new Test(), new Test()]
});

expect(parameters.has('request')).toBe(true);
expect(parameters.has('request.headers')).toBe(true);
expect(parameters.has('request.headers.Content-Type')).toBe(true);
expect(parameters.has('request.headers.Content-type')).toBe(false);
expect(parameters.has('request.unknown')).toBe(false);

expect(klient.url).toBe('http://localhost');
expect(klient.debug).toBe(true);
expect(klient.parameters.get('request.headers.Content-Type')).toBe('application/json');
expect(klient.parameters).toBeInstanceOf(Bag);
expect(parameters.get('request.headers.Content-Type')).toBe('application/json');
expect(parameters).toBeInstanceOf(Bag);

const customParam = klient.parameters.get('customParam');
const customParam = parameters.get('customParam');

expect(customParam).toBeInstanceOf(Array);
expect(customParam.length).toBe(2);
expect(customParam[0]).toBeInstanceOf(Test);
expect(customParam[1]).toBeInstanceOf(Test);

expect(klient.parameters.all()).toBeInstanceOf(Object);
expect(klient.parameters.all()).not.toBeInstanceOf(Bag);
expect(klient.parameters.all().name).toBe('KlientTest');
expect(parameters.all()).toBeInstanceOf(Object);
expect(parameters.all()).not.toBeInstanceOf(Bag);
expect(parameters.all().name).toBe('KlientTest');
});
4 changes: 4 additions & 0 deletions src/services/bag/bag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default class Bag implements BagItems, Watchable {
return getWatchers(this);
}

has(path: string) {
return objectPath.get(this, path) !== undefined;
}

get(path: string) {
return objectPath.get(this.all(), path);
}
Expand Down

0 comments on commit 18353fd

Please sign in to comment.