From ece3d0d7da4f4e85789676c28c7922eb829b00f4 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Wed, 27 Feb 2019 12:48:18 -0500 Subject: [PATCH] Add tests for the build pipeline (#493) * Add tests for the build pipeline. * Improve autobind decorator test. --- .../tests/build-pipeline-dynamic-import.tsx | 3 ++ frontend/lib/tests/build-pipeline.test.tsx | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 frontend/lib/tests/build-pipeline-dynamic-import.tsx create mode 100644 frontend/lib/tests/build-pipeline.test.tsx diff --git a/frontend/lib/tests/build-pipeline-dynamic-import.tsx b/frontend/lib/tests/build-pipeline-dynamic-import.tsx new file mode 100644 index 000000000..2462e8a8c --- /dev/null +++ b/frontend/lib/tests/build-pipeline-dynamic-import.tsx @@ -0,0 +1,3 @@ +export function blah(x: number) { + return x + 1; +} diff --git a/frontend/lib/tests/build-pipeline.test.tsx b/frontend/lib/tests/build-pipeline.test.tsx new file mode 100644 index 000000000..b0bf2a4a9 --- /dev/null +++ b/frontend/lib/tests/build-pipeline.test.tsx @@ -0,0 +1,44 @@ +import autobind from 'autobind-decorator'; + +test("dynamic import works", () => { + return import('./build-pipeline-dynamic-import').then(mod => { + expect(mod.blah(5)).toEqual(6); + }); +}); + +test('autobind decorator works', () => { + class Blarg { + constructor(readonly base: number) {} + + @autobind + boop(x: number) { + return this.base + x; + } + } + + const blarg = new Blarg(6); + const boop = blarg.boop; + + expect(boop(1)).toEqual(7); +}); + +test('super() works', () => { + class Foo { + thingy: number; + + constructor() { + this.thingy = 1; + } + } + + class Bar extends Foo { + constructor() { + super() + this.thingy += 1; + } + } + + const bar = new Bar(); + + expect(bar.thingy).toEqual(2); +});