Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Date reflection bug test suite #448

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"prettier": "^1.5.3",
"react": "latest",
"react-test-renderer": "latest",
"reflect-metadata": "^0.1.12",
"rimraf": "latest",
"ts-jest": "latest",
"tslint": "next",
Expand Down
10 changes: 10 additions & 0 deletions tests/__tests__/metadata-emit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import runJest from '../__helpers__/runJest';

describe('Metadata emit', () => {
it('should run metadata emitting test successfuly', () => {
const result = runJest('../metadata-emit', ['--no-cache']);
const stderr = result.stderr;
expect(result.status).toEqual(0);
expect(stderr).toContain('8 passed, 8 total');
});
});
76 changes: 76 additions & 0 deletions tests/metadata-emit/__tests__/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { TestClass } from '../src/classes';
import { OtherClass } from '../src/other-class';

describe('emit metadata', () => {
it('should emit String for string prop', async () => {
const metadataType = Reflect.getMetadata(
'design:type',
TestClass.prototype,
'stringProp',
);
expect(metadataType).toEqual(String);
});

it('should emit Number for number prop', async () => {
const metadataType = Reflect.getMetadata(
'design:type',
TestClass.prototype,
'numberProp',
);
expect(metadataType).toEqual(Number);
});

it('should emit Boolean for boolean prop', async () => {
const metadataType = Reflect.getMetadata(
'design:type',
TestClass.prototype,
'booleanProp',
);
expect(metadataType).toEqual(Boolean);
});

it('should emit Date for date prop', async () => {
const metadataType = Reflect.getMetadata(
'design:type',
TestClass.prototype,
'dateProp',
);
// expect(metadataType).toEqual(Date);
});

it('should emit Array for array prop', async () => {
const metadataType = Reflect.getMetadata(
'design:type',
TestClass.prototype,
'arrayProp',
);
expect(metadataType).toEqual(Array);
});

it('should emit Array for generic array prop', async () => {
const metadataType = Reflect.getMetadata(
'design:type',
TestClass.prototype,
'genericArrayProp',
);
expect(metadataType).toEqual(Array);
});

it('should emit Function for func prop', async () => {
const metadataType = Reflect.getMetadata(
'design:type',
TestClass.prototype,
'functionProp',
);
expect(metadataType).toEqual(Function);
});

it('should emit class type for class prop', async () => {
const metadataType = Reflect.getMetadata(
'design:type',
TestClass.prototype,
'classProp',
);
expect(metadataType).toEqual(OtherClass);
});
});
16 changes: 16 additions & 0 deletions tests/metadata-emit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"jest": {
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"moduleDirectories": ["node_modules", "src"],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
]
}
}
25 changes: 25 additions & 0 deletions tests/metadata-emit/src/classes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'reflect-metadata';

import { OtherClass } from './other-class';

export const CollectMetadata: PropertyDecorator = () => {
return;
};

export class TestClass {
@CollectMetadata public stringProp: string;

@CollectMetadata public numberProp: number;

@CollectMetadata public booleanProp: boolean;

@CollectMetadata public dateProp: Date;

@CollectMetadata public arrayProp: any[];

@CollectMetadata public genericArrayProp: Array<string | number>;

@CollectMetadata public functionProp: () => void;

@CollectMetadata public classProp: OtherClass;
}
3 changes: 3 additions & 0 deletions tests/metadata-emit/src/other-class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class OtherClass {
public prop: any;
}
14 changes: 14 additions & 0 deletions tests/metadata-emit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": false,
"jsx": "react",
"allowJs": true,
"baseUrl": "src",
"allowSyntheticDefaultImports": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}