Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Damith88 committed Apr 6, 2022
1 parent eed697b commit b55de19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
32 changes: 16 additions & 16 deletions src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,43 +722,43 @@ describe('Sakota', () => {

it('should merge only upto 2 levels', () => {
const entity = {
data: {d1: 'data1'},
data: { d1: 'data1' },
};
const wrapped = Sakota.create(entity);
const modifier = { $set: { 'links.l1': { id: 'l1' } }};
spyOn( console, 'warn' );
const modifier = { $set: { 'links.l1': { id: 'l1' } } };
spyOn(console, 'warn');
wrapped.__sakota__.mergeChanges(modifier);
expect(wrapped).toEqual({
...entity,
links: {
l1: {
id: 'l1'
}
}
id: 'l1',
},
},
} as any);
expect( console.warn ).toHaveBeenCalled();
expect(console.warn).toHaveBeenCalled();
});

it('throw if the modifier is incorrect', () => {
const entity = {
data: {d1: 'data1'},
data: { d1: 'data1' },
};
const wrapped = Sakota.create(entity);
const modifier = { $set: { 'links.l1.data': 'data1' }};
spyOn( console, 'warn' );
const modifier = { $set: { 'links.l1.data': 'data1' } };
spyOn(console, 'warn');
expect(() => wrapped.__sakota__.mergeChanges(modifier)).toThrow();
expect( console.warn ).toHaveBeenCalled();
expect(console.warn).toHaveBeenCalled();
});

it('throw if the modifier is incorrect(2)', () => {
const entity = {
data: {d1: 'data1'},
data: { d1: 'data1' },
};
const wrapped = Sakota.create(entity);
const modifier = { $unset: { 'links.l1': true }};
spyOn( console, 'warn' );
const modifier = { $unset: { 'links.l1': true } };
spyOn(console, 'warn');
expect(() => wrapped.__sakota__.mergeChanges(modifier)).toThrow();
expect( console.warn ).toHaveBeenCalled();
expect(console.warn).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -850,7 +850,7 @@ describe('Sakota', () => {
// class APoint extends Point {}
const obj: any = new Point();
const wrapped = Sakota.create(obj);
wrapped.p = {x: 2, y: 3};
wrapped.p = { x: 2, y: 3 };

const unwrapped = wrapped.__sakota__.unwrap();
expect(unwrapped).toEqual(new Point(2, 3));
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,8 @@ export class Sakota<T extends object> implements ProxyHandler<T> {
val = Object.assign(this.target, $set);
} else {
val = Object.assign({}, this.target, $set);
Object.setPrototypeOf( val, Object.getPrototypeOf( this.target ));
Object.setPrototypeOf(val, Object.getPrototypeOf(this.target));
}

}
$unset.forEach(k => delete val[k]);
return val;
Expand Down

0 comments on commit b55de19

Please sign in to comment.