Skip to content

Commit 3ae2c3f

Browse files
committed
test(reflection): add tests if target is undefined for each method
1 parent 644a654 commit 3ae2c3f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

spec/index.spec.ts

+47
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,53 @@ import { Organization } from '../examples/models/organization';
99
import { Panther } from '../examples/models/panther';
1010
import { Zoo } from '../examples/models/zoo';
1111
import { Employee } from '../examples/models/employee';
12+
import { Reflection } from '../src/reflection';
13+
14+
describe('Reflection', () => {
15+
const unknownTarget: any = undefined;
16+
17+
it('getBaseClass should return undefined if there is no target', () => {
18+
expect(Reflection.getBaseClass(unknownTarget)).toBeUndefined();
19+
});
20+
21+
it('getJsonPropertiesMetadata should return undefined if there is no target', () => {
22+
expect(Reflection.getJsonPropertiesMetadata(unknownTarget)).toBeUndefined();
23+
});
24+
25+
it('getParamTypes should return undefined if there is no target', () => {
26+
expect(Reflection.getParamTypes(unknownTarget)).toBeUndefined();
27+
});
28+
29+
it('getJsonObjectMetadata should return undefined if there is no target', () => {
30+
expect(Reflection.getJsonObjectMetadata(unknownTarget)).toBeUndefined();
31+
});
32+
33+
it('getType should return undefined if there is no target', () => {
34+
expect(Reflection.getType(unknownTarget, 'test')).toBeUndefined();
35+
});
36+
37+
it('isJsonObject should return undefined if there is no target', () => {
38+
expect(Reflection.isJsonObject(unknownTarget)).toBe(false);
39+
});
40+
41+
it('setJsonPropertiesMetadata should not define metadata if there is no target', () => {
42+
const spy = jest.spyOn(Reflect, 'defineMetadata');
43+
Reflection.setJsonPropertiesMetadata({}, unknownTarget);
44+
expect(spy).toHaveBeenCalledTimes(0);
45+
});
46+
47+
it('setJsonObject should not define json object if there is no target', () => {
48+
const spy = jest.spyOn(Reflect, 'defineMetadata');
49+
Reflection.setJsonObject({ baseClassNames: [] }, unknownTarget);
50+
expect(spy).toHaveBeenCalledTimes(0);
51+
});
52+
53+
it('setType should not define type if there is no target', () => {
54+
const spy = jest.spyOn(Reflect, 'defineMetadata');
55+
Reflection.setType('test', unknownTarget, 'test');
56+
expect(spy).toHaveBeenCalledTimes(0);
57+
});
58+
});
1259

1360
describe('JsonObject', () => {
1461
it('should return no metadata', () => {

0 commit comments

Comments
 (0)