From 59ff2e8cf9b4f4a094ff0ec642c69299c74b2ff8 Mon Sep 17 00:00:00 2001 From: Fahrradflucht Date: Mon, 13 Mar 2017 20:11:02 +0100 Subject: [PATCH] test: add failing watch-object-test patch --- src/__test__/watch-object-patch.ts | 94 ++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/__test__/watch-object-patch.ts diff --git a/src/__test__/watch-object-patch.ts b/src/__test__/watch-object-patch.ts new file mode 100644 index 0000000..6343f2a --- /dev/null +++ b/src/__test__/watch-object-patch.ts @@ -0,0 +1,94 @@ +import { + src, webpackConfig, tsconfig, + watch, expectErrors, spec +} from './utils'; + +spec('just patch Object interface', async function() { + src('index.ts', ` + interface Object { + hasOwnProperty(k: K): this is {[_ in K]: any } + } + + interface TypeA {} + interface TypeB { + bar: boolean; + } + + type UnionType = TypeA | TypeB; + + const foo: UnionType = { + bar: true + } + + if (!foo.hasOwnProperty('bar')) { + throw new Error(); + } + + foo.bar + `); + + tsconfig(); + + const watcher = watch(webpackConfig()); + + let stats = await watcher.wait(); + expectErrors(stats, 0); +}); + +spec('patch Object interface and recompile (remove empty line)', async function() { + const index = src('index.ts', ` + interface Object { + hasOwnProperty(k: K): this is {[_ in K]: any } + } + + interface TypeA {} + interface TypeB { + bar: boolean; + } + + type UnionType = TypeA | TypeB; + + const foo: UnionType = { + bar: true + } + + if (!foo.hasOwnProperty('bar')) { + throw new Error(); + } + + foo.bar + `); + + tsconfig(); + + const watcher = watch(webpackConfig()); + + let stats = await watcher.wait(); + expectErrors(stats, 0); + + index.update(() => ` + interface Object { + hasOwnProperty(k: K): this is {[_ in K]: any } + } + + interface TypeA {} + interface TypeB { + bar: boolean; + } + + type UnionType = TypeA | TypeB; + + const foo: UnionType = { + bar: true + } + + if (!foo.hasOwnProperty('bar')) { + throw new Error(); + } + foo.bar + `); + + stats = await watcher.wait(); + + expectErrors(stats, 0); +});