Skip to content

Commit

Permalink
chore: revamp test files
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 27, 2020
1 parent a487e9b commit 4f3369f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
let count = 0;

const foo = {
get a() {
count++;
return {
b() {
return "b" in this && !("a" in this);
}
class Foo {
constructor() {
this.x = 1;
this.self = this;
}
m() { return this.x; };
getSelf() { return this }

test() {
const Foo = this;
const o = { Foo: Foo };
const deep = { very: { o } };
function fn() {
return o;
}
function fnDeep() {
return deep;
}
},
b() {
return "b" in this && "a" in this;

expect((Foo?.["m"])()).toEqual(1);
expect((Foo?.["m"])().toString).toEqual(1..toString);
expect((Foo?.["m"])().toString()).toEqual('1');

expect((o?.Foo.m)()).toEqual(1);
expect((o?.Foo.m)().toString).toEqual(1..toString);
expect((o?.Foo.m)().toString()).toEqual('1');

expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1);
expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1);
}
}

expect((foo?.b)()).toBe(true);
expect((foo?.b)?.()).toBe(true);
expect(() => (undefined?.b)()).toThrow();
testNull() {
const o = null;

expect(() => { (o?.Foo.m)() }).toThrow();
expect(() => { (o?.Foo.m)().toString }).toThrow();
expect(() => { (o?.Foo.m)().toString() }).toThrow();

expect((foo?.a.b)()).toBe(true);
expect(count).toBe(1);
expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow();
expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow();
}
}

expect((foo?.a.b)?.()).toBe(true);
expect(count).toBe(2);
(new Foo).test();
(new Foo).testNull();
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
(foo?.bar)();
class Foo {
constructor() {
this.x = 1;
this.self = this;
}
m() { return this.x; };
getSelf() { return this }

(foo?.bar)?.();
test() {
const Foo = this;
const o = { Foo: Foo };

(foo?.bar.baz)();
(Foo?.["m"])();
(Foo?.["m"])().toString;
(Foo?.["m"])().toString();

(foo?.bar.baz)?.();
(o?.Foo.m)();
(o?.Foo.m)().toString;
(o?.Foo.m)().toString();

(((o.Foo?.self.getSelf)())?.m)();
(((o.Foo.self?.getSelf)())?.m)();
}
}

(new Foo).test();
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
var _foo, _foo2, _foo2$bar, _foo3, _foo3$bar, _foo4, _foo4$bar$baz, _foo4$bar;
class Foo {
constructor() {
this.x = 1;
this.self = this;
}

((_foo = foo) === null || _foo === void 0 ? void 0 : _foo.bar.bind(_foo))();
(_foo2 = foo) === null || _foo2 === void 0 ? void 0 : (_foo2$bar = _foo2.bar) === null || _foo2$bar === void 0 ? void 0 : _foo2$bar.call(_foo2);
((_foo3 = foo) === null || _foo3 === void 0 ? void 0 : (_foo3$bar = _foo3.bar).baz.bind(_foo3$bar))();
(_foo4 = foo) === null || _foo4 === void 0 ? void 0 : (_foo4$bar$baz = (_foo4$bar = _foo4.bar).baz) === null || _foo4$bar$baz === void 0 ? void 0 : _foo4$bar$baz.call(_foo4$bar);
m() {
return this.x;
}

getSelf() {
return this;
}

test() {
var _o$Foo, _o$Foo2, _o$Foo3, _o$Foo$self$getSelf, _o$Foo4, _o$Foo4$self, _o$Foo$self$getSelf2, _o$Foo$self;

const Foo = this;
const o = {
Foo: Foo
};
(Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))();
(Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString;
(Foo === null || Foo === void 0 ? void 0 : Foo["m"].bind(Foo))().toString();
(o === null || o === void 0 ? void 0 : (_o$Foo = o.Foo).m.bind(_o$Foo))();
(o === null || o === void 0 ? void 0 : (_o$Foo2 = o.Foo).m.bind(_o$Foo2))().toString;
(o === null || o === void 0 ? void 0 : (_o$Foo3 = o.Foo).m.bind(_o$Foo3))().toString();
((_o$Foo$self$getSelf = ((_o$Foo4 = o.Foo) === null || _o$Foo4 === void 0 ? void 0 : (_o$Foo4$self = _o$Foo4.self).getSelf.bind(_o$Foo4$self))()) === null || _o$Foo$self$getSelf === void 0 ? void 0 : _o$Foo$self$getSelf.m.bind(_o$Foo$self$getSelf))();
((_o$Foo$self$getSelf2 = ((_o$Foo$self = o.Foo.self) === null || _o$Foo$self === void 0 ? void 0 : _o$Foo$self.getSelf.bind(_o$Foo$self))()) === null || _o$Foo$self$getSelf2 === void 0 ? void 0 : _o$Foo$self$getSelf2.m.bind(_o$Foo$self$getSelf2))();
}

}

new Foo().test();

0 comments on commit 4f3369f

Please sign in to comment.