From 2defe94b1f9c7eb41565b0440832e574b6abb32e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 24 Aug 2015 12:47:39 -0700 Subject: [PATCH] Added test for transpilation with emitting of metadata and decorator --- tests/cases/unittests/transpile.ts | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index c222e2ebb82..0b87910d26e 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -220,6 +220,55 @@ var x = 0;`, expectedOutput: output }); }); + + it("Transpile with emit decorators and emit metadata", () => { + let input = + `import {db} from './db';\n` + + `function someDecorator(target) {\n` + + ` return target;\n` + + `} \n` + + `@someDecorator\n` + + `class MyClass {\n` + + ` db: db;\n` + + ` constructor(db: db) {\n` + + ` this.db = db;\n` + + ` this.db.doSomething(); \n` + + ` }\n` + + `}\n` + + `export {MyClass}; \n` + let output = + `var db_1 = require(\'./db\');\n` + + `function someDecorator(target) {\n` + + ` return target;\n` + + `}\n` + + `var MyClass = (function () {\n` + + ` function MyClass(db) {\n` + + ` this.db = db;\n` + + ` this.db.doSomething();\n` + + ` }\n` + + ` MyClass = __decorate([\n` + + ` someDecorator, \n` + + ` __metadata(\'design:paramtypes\', [(typeof (_a = typeof db_1.db !== \'undefined\' && db_1.db) === \'function\' && _a) || Object])\n` + + ` ], MyClass);\n` + + ` return MyClass;\n` + + ` var _a;\n` + + `})();\n` + + `exports.MyClass = MyClass;\n`; + test(input, + { + options: { + compilerOptions: { + module: ModuleKind.CommonJS, + newLine: NewLineKind.LineFeed, + noEmitHelpers: true, + emitDecoratorMetadata: true, + experimentalDecorators: true, + target: ScriptTarget.ES5, + } + }, + expectedOutput: output + }); + }); }); }