Add tests

This commit is contained in:
Mohamed Hegazy 2016-01-07 14:33:47 -08:00
parent cc1947b94f
commit 1e433bfb4f
11 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,20 @@
//// [tests/cases/compiler/reactNamespaceImportPresevation.tsx] ////
//// [modules.d.ts]
declare module "my-React-Lib" {
var a: any;
export = a;
}
//// [test.tsx]
import * as myReactLib from "my-React-Lib"; // should not be elided
declare var foo: any;
<foo data/>;
//// [test.jsx]
"use strict";
var myReactLib = require("my-React-Lib"); // should not be elided
<foo data/>;

View File

@ -0,0 +1,20 @@
=== tests/cases/compiler/modules.d.ts ===
declare module "my-React-Lib" {
var a: any;
>a : Symbol(a, Decl(modules.d.ts, 2, 7))
export = a;
>a : Symbol(a, Decl(modules.d.ts, 2, 7))
}
=== tests/cases/compiler/test.tsx ===
import * as myReactLib from "my-React-Lib"; // should not be elided
>myReactLib : Symbol(myReactLib, Decl(test.tsx, 0, 6))
declare var foo: any;
>foo : Symbol(foo, Decl(test.tsx, 1, 11))
<foo data/>;
>data : Symbol(unknown)

View File

@ -0,0 +1,22 @@
=== tests/cases/compiler/modules.d.ts ===
declare module "my-React-Lib" {
var a: any;
>a : any
export = a;
>a : any
}
=== tests/cases/compiler/test.tsx ===
import * as myReactLib from "my-React-Lib"; // should not be elided
>myReactLib : any
declare var foo: any;
>foo : any
<foo data/>;
><foo data/> : any
>foo : any
>data : any

View File

@ -0,0 +1,20 @@
//// [reactNamespaceJSXEmit.tsx]
declare var myReactLib: any;
declare var foo: any;
declare var Bar: any;
declare var x: any;
<foo data/>;
<Bar x={x} />;
<x-component />;
<Bar {...x} />;
<Bar { ...x } y={2} />;
//// [reactNamespaceJSXEmit.js]
myReactLib.createElement("foo", {data: true});
myReactLib.createElement(Bar, {x: x});
myReactLib.createElement("x-component", null);
myReactLib.createElement(Bar, myReactLib.__spread({}, x));
myReactLib.createElement(Bar, myReactLib.__spread({}, x, {y: 2}));

View File

@ -0,0 +1,32 @@
=== tests/cases/compiler/reactNamespaceJSXEmit.tsx ===
declare var myReactLib: any;
>myReactLib : Symbol(myReactLib, Decl(reactNamespaceJSXEmit.tsx, 1, 11))
declare var foo: any;
>foo : Symbol(foo, Decl(reactNamespaceJSXEmit.tsx, 2, 11))
declare var Bar: any;
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
declare var x: any;
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))
<foo data/>;
>data : Symbol(unknown)
<Bar x={x} />;
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
>x : Symbol(unknown)
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))
<x-component />;
<Bar {...x} />;
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))
<Bar { ...x } y={2} />;
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))
>y : Symbol(unknown)

View File

@ -0,0 +1,41 @@
=== tests/cases/compiler/reactNamespaceJSXEmit.tsx ===
declare var myReactLib: any;
>myReactLib : any
declare var foo: any;
>foo : any
declare var Bar: any;
>Bar : any
declare var x: any;
>x : any
<foo data/>;
><foo data/> : any
>foo : any
>data : any
<Bar x={x} />;
><Bar x={x} /> : any
>Bar : any
>x : any
>x : any
<x-component />;
><x-component /> : any
>x-component : any
<Bar {...x} />;
><Bar {...x} /> : any
>Bar : any
>x : any
<Bar { ...x } y={2} />;
><Bar { ...x } y={2} /> : any
>Bar : any
>x : any
>y : any
>2 : number

View File

@ -0,0 +1,9 @@
tests/cases/compiler/reactNamespaceMissingDeclaration.tsx(3,2): error TS2304: Cannot find name 'myReactLib'.
==== tests/cases/compiler/reactNamespaceMissingDeclaration.tsx (1 errors) ====
// Error myReactLib not declared
<foo data/>
~~~
!!! error TS2304: Cannot find name 'myReactLib'.

View File

@ -0,0 +1,8 @@
//// [reactNamespaceMissingDeclaration.tsx]
// Error myReactLib not declared
<foo data/>
//// [reactNamespaceMissingDeclaration.js]
// Error myReactLib not declared
myReactLib.createElement("foo", {data: true});

View File

@ -0,0 +1,15 @@
//@jsx: preserve
//@module: commonjs
//@reactNamespace: myReactLib
//@filename: modules.d.ts
declare module "my-React-Lib" {
var a: any;
export = a;
}
//@filename: test.tsx
import * as myReactLib from "my-React-Lib"; // should not be elided
declare var foo: any;
<foo data/>;

View File

@ -0,0 +1,13 @@
//@jsx: react
//@reactNamespace: myReactLib
declare var myReactLib: any;
declare var foo: any;
declare var Bar: any;
declare var x: any;
<foo data/>;
<Bar x={x} />;
<x-component />;
<Bar {...x} />;
<Bar { ...x } y={2} />;

View File

@ -0,0 +1,5 @@
//@jsx: react
//@reactNamespace: myReactLib
// Error myReactLib not declared
<foo data/>