Skip to content

Commit

Permalink
Tests WIP 4
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 26, 2023
1 parent 38ca5bb commit 7b42b5c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

* Prevent injection of class into scope function for its methods.

* Tests for `class extends Object {}` and `class extends Function {}`

* Tests for `super()` in arrow functions:

```js
Expand Down
58 changes: 58 additions & 0 deletions test/classes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,64 @@ describe('Classes', () => {
});
});

describe('defaults', () => {
itSerializes('Object', {
in() {
return class extends Object {};
},
out: `(()=>{
const a=Object,
b=a.setPrototypeOf,
c=b(class extends class{}{},a);
b(c.prototype,a.prototype);
return c
})()`,
validate(Klass) {
expect(Klass).toBeFunction();
expect(Klass).toHavePrototype(Object);
expect(Klass.prototype).toHavePrototype(Object.prototype);
}
});

itSerializes('Function', {
in() {
return class extends Function {};
},
out: `(()=>{
const a=Object.setPrototypeOf,
b=Function,
c=a(class extends class{}{},b);
a(c.prototype,b.prototype);
return c
})()`,
validate(Klass) {
expect(Klass).toBeFunction();
expect(Klass).toHavePrototype(Function);
expect(Klass.prototype).toHavePrototype(Function.prototype);
}
});

itSerializes('Function.prototype', {
in() {
class X extends Object {}
Object.setPrototypeOf(X, Function.prototype);
return X;
},
out: `(()=>{
const a=Object,
b=a.setPrototypeOf,
c=b(class X extends class{}{},Function.prototype);
b(c.prototype,a.prototype);
return c
})()`,
validate(Klass) {
expect(Klass).toBeFunction();
expect(Klass).toHavePrototype(Function.prototype);
expect(Klass.prototype).toHavePrototype(Object.prototype);
}
});
});

itSerializes("defined in another class method's computed key", {
in() {
let Klass;
Expand Down

0 comments on commit 7b42b5c

Please sign in to comment.