Skip to content

Commit

Permalink
fix: formatting for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGw committed Apr 26, 2024
1 parent c9fd003 commit cd39589
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,6 @@ export function Frozen<T extends Newable>(cst: T): T & Newable {
};
}


const _seal = (obj: object) => {
Object.seal(obj);
};
Expand All @@ -1719,15 +1718,15 @@ const _seal = (obj: object) => {
* john.age = 31; // Allowed
*
* // Existing properties cannot be re-configured or deleted
* delete john.age; // TypeError: Cannot delete property 'age'
* }
* ```
* */
* delete john.age; // TypeError: Cannot delete property 'age'
* }
* ```
* */
export function Sealed<T extends Newable>(cst: T): T & Newable {
return class Locked extends cst {
constructor(...args: any[]) {
super(...args);
_seal(this);
}
};
}
}
34 changes: 17 additions & 17 deletions tests/sealed-class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,23 @@ test('Should be allowed to mutate the properties of a sealed object', () => {
});

test('Should not allow to delete the properties of a sealed object', () => {
@Sealed
class Foo<T> {
private _foo: T;
bar?: string;
constructor(foo: T) {
this._foo = foo;
this.bar = 'bar';
}
someFoo(): T {
return this._foo;
}
}
expect(() => {
delete new Foo('foo').bar;
}).toThrow(TypeError);
});
@Sealed
class Foo<T> {
private _foo: T;
bar?: string;

constructor(foo: T) {
this._foo = foo;
this.bar = 'bar';
}
someFoo(): T {
return this._foo;
}
}
expect(() => {
delete new Foo('foo').bar;
}).toThrow(TypeError);
});

test('Should work when the final class is a subclass itself', () => {
abstract class BaseFoo<T> {
Expand Down

0 comments on commit cd39589

Please sign in to comment.