MCPcopy
hub / github.com/loopbackio/loopback-next / runTests

Function runTests

packages/metadata/src/__tests__/unit/reflect.unit.ts:36–521  ·  view source on GitHub ↗
(reflectContext: NamespacedReflect)

Source from the content-addressed store, hash-verified

34 });
35
36 function runTests(reflectContext: NamespacedReflect) {
37 afterEach(resetMetadata);
38
39 it('adds metadata to a class', () => {
40 const metadataValue: object = {value: 'sample'};
41 // define a metadata using the namespaced reflectContext
42 reflectContext.defineMetadata('key', metadataValue, SubClass);
43
44 // get the defined metadata using the namespaced reflectContext
45 let metadata = reflectContext.getMetadata('key', SubClass);
46 expect(metadata).to.be.equal(metadataValue);
47
48 metadata = reflectContext.getOwnMetadata('key', SubClass);
49 expect(metadata).to.be.equal(metadataValue);
50
51 // base class should not be impacted
52 metadata = reflectContext.getOwnMetadata('key', BaseClass);
53 expect(metadata).to.be.undefined();
54
55 metadata = reflectContext.getMetadata('key', BaseClass);
56 expect(metadata).to.be.undefined();
57
58 let result = reflectContext.hasOwnMetadata('key', SubClass);
59 expect(result).to.be.true();
60
61 result = reflectContext.hasMetadata('key', SubClass);
62 expect(result).to.be.true();
63 });
64
65 it('adds metadata to a static method', () => {
66 const metadataValue: object = {value: 'sample'};
67 // define a metadata using the namespaced reflectContext
68 reflectContext.defineMetadata(
69 'key',
70 metadataValue,
71 SubClass,
72 'subStaticMethod',
73 );
74
75 // get the defined metadata using the namespaced reflectContext
76 let metadata = reflectContext.getMetadata(
77 'key',
78 SubClass,
79 'subStaticMethod',
80 );
81 expect(metadata).to.be.equal(metadataValue);
82
83 metadata = reflectContext.getOwnMetadata(
84 'key',
85 SubClass,
86 'subStaticMethod',
87 );
88 expect(metadata).to.be.equal(metadataValue);
89
90 let result = reflectContext.hasOwnMetadata(
91 'key',
92 SubClass,
93 'subStaticMethod',

Callers 1

reflect.unit.tsFile · 0.70

Calls 13

getMetadataMethod · 0.80
getOwnMetadataMethod · 0.80
undefinedMethod · 0.80
hasOwnMetadataMethod · 0.80
trueMethod · 0.80
hasMetadataMethod · 0.80
deleteMetadataMethod · 0.80
falseMethod · 0.80
eqlMethod · 0.80
getMetadataKeysMethod · 0.80
getOwnMetadataKeysMethod · 0.80
equalMethod · 0.65

Tested by

no test coverage detected