How to use parsePropMetadataParserInput method in ng-mocks

Best JavaScript code snippet using ng-mocks

collect-declarations.ts

Source: collect-declarations.ts Github

copy

Full Screen

1import { ɵReflectionCapabilities as ReflectionCapabilities } from '@angular/​core';2import coreDefineProperty from '../​common/​core.define-property';3import { AnyDeclaration } from '../​common/​core.types';4interface Declaration {5 host: Record<string, string | undefined>;6 hostBindings: Array<[string, string?, ...any[]]>;7 hostListeners: Array<[string, string?, ...any[]]>;8 attributes: string[];9 inputs: string[];10 outputs: string[];11 propDecorators: Record<string, any[]>;12 queries: Record<string, any>;13 decorators: Array<'Injectable' | 'Pipe' | 'Directive' | 'Component' | 'NgModule'>;14 [key: string]: any;15}16const pushDecorator = (decorators: string[], decorator: string): void => {17 const deleteIndex = decorators.indexOf(decorator);18 if (deleteIndex !== -1) {19 decorators.splice(deleteIndex, 1);20 }21 if (22 decorator === 'Injectable' ||23 decorator === 'Pipe' ||24 decorator === 'Directive' ||25 decorator === 'Component' ||26 decorator === 'NgModule'27 ) {28 decorators.push(decorator);29 }30};31const getAllKeys = <T extends Record<keyof any, any>>(instance: T): Array<keyof T> => {32 const props: string[] = [];33 for (const key of Object.keys(instance)) {34 props.push(key);35 }36 return props as never;37};38const createDeclarations = (parent: Partial<Declaration>): Declaration => ({39 host: parent.host ? { ...parent.host } : {},40 hostBindings: parent.hostBindings ? [...parent.hostBindings] : [],41 hostListeners: parent.hostListeners ? [...parent.hostListeners] : [],42 attributes: parent.attributes ? [...parent.attributes] : [],43 inputs: parent.inputs ? [...parent.inputs] : [],44 outputs: parent.outputs ? [...parent.outputs] : [],45 propDecorators: parent.propDecorators ? { ...parent.propDecorators } : {},46 queries: parent.queries ? { ...parent.queries } : {},47 decorators: parent.decorators ? [...parent.decorators] : [],48});49const parseParameters = (50 def: {51 __parameters__?: Array<null | Array<52 | {53 attributeName: string;54 ngMetadataName: 'Attribute';55 }56 | {57 token: AnyDeclaration<any>;58 ngMetadataName: 'Inject';59 }60 | {61 ngMetadataName: 'Optional';62 }63 >>;64 },65 declaration: Declaration,66): void => {67 if (Object.prototype.hasOwnProperty.call(def, '__parameters__') && def.__parameters__) {68 for (const decorators of def.__parameters__) {69 for (const decorator of decorators || []) {70 if (71 decorator.ngMetadataName === 'Attribute' &&72 declaration.attributes.indexOf(decorator.attributeName) === -173 ) {74 declaration.attributes.push(decorator.attributeName);75 }76 }77 }78 }79};80const parseAnnotations = (81 def: {82 __annotations__?: Array<{83 ngMetadataName?: string;84 }>;85 },86 declaration: Declaration,87): void => {88 if (Object.prototype.hasOwnProperty.call(def, '__annotations__') && def.__annotations__) {89 for (const annotation of def.__annotations__) {90 const ngMetadataName = annotation?.ngMetadataName;91 if (!ngMetadataName) {92 continue;93 }94 declaration[ngMetadataName] = { ...annotation, attributes: declaration.attributes };95 pushDecorator(declaration.decorators, ngMetadataName);96 }97 }98};99const parseDecorators = (100 def: {101 decorators?: Array<{102 args?: [any];103 type?: {104 prototype?: {105 ngMetadataName?: string;106 };107 };108 }>;109 },110 declaration: Declaration,111): void => {112 if (Object.prototype.hasOwnProperty.call(def, 'decorators') && def.decorators) {113 for (const decorator of def.decorators) {114 const ngMetadataName = decorator?.type?.prototype?.ngMetadataName;115 if (!ngMetadataName) {116 continue;117 }118 declaration[ngMetadataName] = decorator.args ? { ...decorator.args[0] } : {};119 pushDecorator(declaration.decorators, ngMetadataName);120 }121 }122};123const parsePropDecoratorsParserFactoryProp =124 (key: 'inputs' | 'outputs') =>125 (126 _: string,127 prop: string,128 decorator: {129 args?: [string];130 },131 declaration: Declaration,132 ): void => {133 const value = prop + (decorator.args?.[0] ? `: ${decorator.args[0]}` : '');134 if (declaration[key].indexOf(value) === -1) {135 declaration[key].unshift(value);136 }137 };138const parsePropDecoratorsParserInput = parsePropDecoratorsParserFactoryProp('inputs');139const parsePropDecoratorsParserOutput = parsePropDecoratorsParserFactoryProp('outputs');140const parsePropDecoratorsParserFactoryQuery =141 (isViewQuery: boolean) =>142 (143 ngMetadataName: string,144 prop: string,145 decorator: {146 args: [string] | [string, any];147 },148 declaration: Declaration,149 ): void => {150 if (!declaration.queries[prop]) {151 declaration.queries[prop] = {152 isViewQuery,153 ngMetadataName,154 selector: decorator.args[0],155 ...decorator.args[1],156 };157 }158 };159const parsePropDecoratorsParserContent = parsePropDecoratorsParserFactoryQuery(false);160const parsePropDecoratorsParserView = parsePropDecoratorsParserFactoryQuery(true);161const parsePropDecoratorsParserHostBinding = (162 _: string,163 prop: string,164 decorator: {165 args?: [string] | [string, any[]];166 },167 declaration: Declaration,168): void => {169 const key = `[${decorator.args?.[0] || prop}]`;170 if (!declaration.host[key]) {171 declaration.host[key] = prop;172 }173 declaration.hostBindings.push([prop, ...(decorator.args || [])]);174};175const parsePropDecoratorsParserHostListener = (176 _: string,177 prop: string,178 decorator: {179 args?: any[];180 },181 declaration: Declaration,182): void => {183 const key = `(${decorator.args?.[0] || prop})`;184 if (!declaration.host[key]) {185 declaration.host[key] = `${prop}($event)`;186 }187 declaration.hostListeners.push([prop, ...(decorator.args || [])]);188};189const parsePropDecoratorsMap: any = {190 ContentChild: parsePropDecoratorsParserContent,191 ContentChildren: parsePropDecoratorsParserContent,192 HostBinding: parsePropDecoratorsParserHostBinding,193 HostListener: parsePropDecoratorsParserHostListener,194 Input: parsePropDecoratorsParserInput,195 Output: parsePropDecoratorsParserOutput,196 ViewChild: parsePropDecoratorsParserView,197 ViewChildren: parsePropDecoratorsParserView,198};199const parsePropDecorators = (200 def: {201 propDecorators?: Record<202 string,203 Array<{204 args: any;205 type?: {206 prototype?: {207 ngMetadataName?: string;208 };209 };210 }>211 >;212 },213 declaration: Declaration,214): void => {215 if (Object.prototype.hasOwnProperty.call(def, 'propDecorators') && def.propDecorators) {216 for (const prop of getAllKeys(def.propDecorators)) {217 declaration.propDecorators[prop] = [...(declaration.propDecorators[prop] || []), ...def.propDecorators[prop]];218 for (const decorator of def.propDecorators[prop]) {219 const ngMetadataName = decorator?.type?.prototype?.ngMetadataName;220 if (!ngMetadataName) {221 continue;222 }223 parsePropDecoratorsMap[ngMetadataName]?.(ngMetadataName, prop, decorator, declaration);224 }225 }226 }227};228const parsePropMetadataParserFactoryProp =229 (key: 'inputs' | 'outputs') =>230 (231 _: string,232 prop: string,233 decorator: {234 bindingPropertyName?: string;235 },236 declaration: Declaration,237 ): void => {238 const value = prop + (decorator.bindingPropertyName ? `: ${decorator.bindingPropertyName}` : '');239 if (declaration[key].indexOf(value) === -1) {240 declaration[key].unshift(value);241 }242 };243const parsePropMetadataParserInput = parsePropMetadataParserFactoryProp('inputs');244const parsePropMetadataParserOutput = parsePropMetadataParserFactoryProp('outputs');245const parsePropMetadataParserFactoryQueryChild =246 (isViewQuery: boolean) =>247 (248 ngMetadataName: string,249 prop: string,250 decorator: {251 read?: any;252 selector: string;253 static?: boolean;254 },255 declaration: Declaration,256 ): void => {257 if (!declaration.queries[prop]) {258 declaration.queries[prop] = {259 isViewQuery,260 ngMetadataName,261 selector: decorator.selector,262 ...(decorator.read !== undefined ? { read: decorator.read } : {}),263 ...(decorator.static !== undefined ? { static: decorator.static } : {}),264 };265 }266 };267const parsePropMetadataParserContentChild = parsePropMetadataParserFactoryQueryChild(false);268const parsePropMetadataParserViewChild = parsePropMetadataParserFactoryQueryChild(true);269const parsePropMetadataParserFactoryQueryChildren =270 (isViewQuery: boolean) =>271 (272 ngMetadataName: string,273 prop: string,274 decorator: {275 descendants?: any;276 emitDistinctChangesOnly?: boolean;277 read?: any;278 selector: string;279 },280 declaration: Declaration,281 ): void => {282 if (!declaration.queries[prop]) {283 declaration.queries[prop] = {284 isViewQuery,285 ngMetadataName,286 selector: decorator.selector,287 ...(decorator.descendants !== undefined ? { descendants: decorator.descendants } : {}),288 ...(decorator.emitDistinctChangesOnly !== undefined289 ? { emitDistinctChangesOnly: decorator.emitDistinctChangesOnly }290 : {}),291 ...(decorator.read !== undefined ? { read: decorator.read } : {}),292 };293 }294 };295const parsePropMetadataParserContentChildren = parsePropMetadataParserFactoryQueryChildren(false);296const parsePropMetadataParserViewChildren = parsePropMetadataParserFactoryQueryChildren(true);297const parsePropMetadataParserHostBinding = (298 _: string,299 prop: string,300 decorator: {301 args?: any;302 hostPropertyName?: string;303 },304 declaration: Declaration,305): void => {306 const key = `[${decorator.hostPropertyName || prop}]`;307 if (!declaration.host[key]) {308 declaration.host[key] = prop;309 }310 declaration.hostBindings.push([311 prop,312 decorator.hostPropertyName || prop,313 ...(decorator.args ? [decorator.args] : []),314 ]);315};316const parsePropMetadataParserHostListener = (317 _: string,318 prop: string,319 decorator: {320 args?: any;321 eventName?: string;322 },323 declaration: Declaration,324): void => {325 const key = `(${decorator.eventName || prop})`;326 if (!declaration.host[key]) {327 declaration.host[key] = `${prop}($event)`;328 }329 declaration.hostListeners.push([prop, decorator.eventName || prop, ...(decorator.args ? [decorator.args] : [])]);330};331const parsePropMetadataMap: any = {332 ContentChild: parsePropMetadataParserContentChild,333 ContentChildren: parsePropMetadataParserContentChildren,334 HostBinding: parsePropMetadataParserHostBinding,335 HostListener: parsePropMetadataParserHostListener,336 Input: parsePropMetadataParserInput,337 Output: parsePropMetadataParserOutput,338 ViewChild: parsePropMetadataParserViewChild,339 ViewChildren: parsePropMetadataParserViewChildren,340};341const parsePropMetadata = (342 def: {343 __prop__metadata__?: Record<keyof any, any[]>;344 },345 declaration: Declaration,346): void => {347 if (Object.prototype.hasOwnProperty.call(def, '__prop__metadata__') && def.__prop__metadata__) {348 for (const prop of getAllKeys(def.__prop__metadata__)) {349 const decorators: Array<{350 ngMetadataName?: string;351 }> = def.__prop__metadata__[prop];352 for (const decorator of decorators) {353 const ngMetadataName = decorator?.ngMetadataName;354 if (!ngMetadataName) {355 continue;356 }357 parsePropMetadataMap[ngMetadataName]?.(ngMetadataName, prop, decorator, declaration);358 }359 }360 }361};362const buildDeclaration = (def: any | undefined, declaration: Declaration): void => {363 if (def) {364 def.inputs = def.inputs || [];365 for (const input of declaration.inputs) {366 if (def.inputs.indexOf(input) === -1) {367 def.inputs.push(input);368 }369 }370 def.outputs = def.outputs || [];371 for (const output of declaration.outputs) {372 if (def.outputs.indexOf(output) === -1) {373 def.outputs.push(output);374 }375 }376 def.queries = {377 ...(def.queries || []),378 ...declaration.queries,379 };380 def.hostBindings = declaration.hostBindings;381 def.hostListeners = declaration.hostListeners;382 }383};384const reflectionCapabilities = new ReflectionCapabilities();385const parse = (def: any): any => {386 if (typeof def !== 'function' && typeof def !== 'object') {387 return {};388 }389 if (Object.prototype.hasOwnProperty.call(def, '__ngMocksParsed')) {390 return def.__ngMocksDeclarations;391 }392 const parent = Object.getPrototypeOf(def);393 const parentDeclarations = parent ? parse(parent) : {};394 const declaration = createDeclarations(parentDeclarations);395 coreDefineProperty(def, '__ngMocksParsed', true);396 parseParameters(def, declaration);397 parseAnnotations(def, declaration);398 parseDecorators(def, declaration);399 parsePropDecorators(def, declaration);400 parsePropMetadata(def, declaration);401 buildDeclaration(declaration.Directive, declaration);402 buildDeclaration(declaration.Component, declaration);403 coreDefineProperty(def, '__ngMocksDeclarations', {404 ...parentDeclarations,405 ...declaration,406 parameters: reflectionCapabilities.parameters(def),407 });408 return def.__ngMocksDeclarations;409};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parsePropMetadataParserInput } from 'ng-mocks';2import { Component, Input } from '@angular/​core';3@Component({4})5export class TestComponent {6 @Input() test: string;7}8const data = parsePropMetadataParserInput(TestComponent, 'test');9console.log(data);10{11}12import { parsePropMetadataParserInput } from 'ng-mocks';13import { Component, Input } from '@angular/​core';14@Component({15})16export class TestComponent {17 @Input() test: string;18}19const data = parsePropMetadataParserInput(TestComponent, 'test', { type: 'string' });20console.log(data);21{22}23import { parsePropMetadataParserInput } from 'ng-mocks';24import { Component, Input } from '@angular/​core';25@Component({26})27export class TestComponent {28 @Input() test: string;29}30const data = parsePropMetadataParserInput(TestComponent, 'test', { type: 'string', name: 'test' });31console.log(data);32{33}34import { parsePropMetadataParserInput } from 'ng-mocks';35import { Component, Input } from '@angular/​core';36@Component({37})38export class TestComponent {39 @Input() test: string;40}41const data = parsePropMetadataParserInput(TestComponent, 'test', { type: 'string', name: 'test', decorators: [{ args: ['test'], type: 'Input' }] });

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parsePropMetadataParserInput } from 'ng-mocks';2const metadata = parsePropMetadataParserInput({3 props: {4 test: {5 }6 }7});8import { parsePropMetadataParserInput } from 'ng-mocks';9const metadata = parsePropMetadataParserInput({10 props: {11 test: {12 }13 }14});15import { parsePropMetadataParserInput } from 'ng-mocks';16const metadata = parsePropMetadataParserInput({17 props: {18 test: {19 }20 }21});22import { parsePropMetadataParserInput } from 'ng-mocks';23const metadata = parsePropMetadataParserInput({24 props: {25 test: {26 }27 }28});29import { parsePropMetadataParserInput } from 'ng-mocks';30const metadata = parsePropMetadataParserInput({31 props: {32 test: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const parsePropMetadataParserInput = require('ng-mocks').parsePropMetadataParserInput;2const metadata = parsePropMetadataParserInput({3});4console.log(metadata);5const parsePropMetadataParserInput = require('ng-mocks').parsePropMetadataParserInput;6const metadata = parsePropMetadataParserInput({7}, 'prop1');8console.log(metadata);9const parsePropMetadataParserInput = require('ng-mocks').parsePropMetadataParserInput;10const metadata = parsePropMetadataParserInput({11}, ['prop1', 'prop2']);12console.log(metadata);13const parsePropMetadataParserInput = require('ng-mocks').parsePropMetadataParserInput;14const metadata = parsePropMetadataParserInput({15}, 'prop3');16console.log(metadata);17const parsePropMetadataParserInput = require('ng-mocks').parsePropMetadataParserInput;18const metadata = parsePropMetadataParserInput({19}, ['prop3', 'prop4']);20console.log(metadata);21const parsePropMetadataParserInput = require('ng-mocks').parsePropMetadataParserInput;22const metadata = parsePropMetadataParserInput({23}, ['prop1', 'prop3

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parsePropMetadataParserInput } from 'ng-mocks';2const parsedInput = parsePropMetadataParserInput({3});4import { parsePropMetadataParserOutput } from 'ng-mocks';5const parsedOutput = parsePropMetadataParserOutput({6});7import { parsePropMetadataParser } from 'ng-mocks';8const parsed = parsePropMetadataParser({9});10import { parsePropMetadata } from 'ng-mocks';11const parsed = parsePropMetadata({12});13import { parsePropMetadataParserOutput } from 'ng-mocks';14const parsedOutput = parsePropMetadataParserOutput({15});16import { parsePropMetadataParser } from 'ng-mocks';17const parsed = parsePropMetadataParser({18});19import { parsePropMetadata } from 'ng-mocks';20const parsed = parsePropMetadata({21});22import { parsePropMetadataParserInput } from 'ng-mocks';23const parsedInput = parsePropMetadataParserInput({24});25import { parsePropMetadataParserOutput } from 'ng-mocks';26const parsedOutput = parsePropMetadataParserOutput({27});28import { parsePropMetadataParser } from 'ng-mocks';29const parsed = parsePropMetadataParser({

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parsePropMetadataParserInput } from 'ng-mocks';2export class TestComponent {3 @Input() public data: any;4}5export const testComponentMetadata = parsePropMetadataParserInput(TestComponent);6describe('TestComponent', () => {7 it('should have data as input', () => {8 expect(testComponentMetadata.inputs).toEqual(['data']);9 });10});11import { parsePropMetadataParserInput } from 'ng-mocks';12export class TestComponent {13 @Input() public data: any;14}15export const testComponentMetadata = parsePropMetadataParserInput(TestComponent);16describe('TestComponent', () => {17 it('should have data as input', () => {18 expect(testComponentMetadata.inputs).toEqual(['data']);19 });20});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parsePropMetadataParserInput } from 'ng-mocks';2describe('test', () => {3 it('should parse', () => {4 let result = parsePropMetadataParserInput({5 });6 console.log(result);7 });8});9import { Component } from '@angular/​core';10@Component({11})12export class TestComponent {}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parsePropMetadataParserInput } = require('ng-mocks');2const { PropMetadata } = require('@angular/​core');3const propMetadata = parsePropMetadataParserInput({4 props: {5 },6});7console.log(propMetadata);8{ myProp: [PropMetadata] }9const { parsePropMetadataParserInput } = require('ng-mocks');10const { PropMetadata } = require('@angular/​core');11const propMetadata = parsePropMetadataParserInput({12 props: {13 },14});15console.log(propMetadata);16{ myProp: [PropMetadata] }17const { parsePropMetadataParserInput } = require('ng-mocks');18const { PropMetadata } = require('@angular/​core');19const propMetadata = parsePropMetadataParserInput({20 props: {21 },22});23console.log(propMetadata);24{ myProp: [PropMetadata] }25const { parsePropMetadataParserInput } = require('ng-mocks');26const { PropMetadata } = require('@angular/​core');27const propMetadata = parsePropMetadataParserInput({28 props: {29 },30});31console.log(propMetadata);32{ myProp: [PropMetadata] }33const { parsePropMetadataParserInput } = require('ng-mocks');34const { PropMetadata } = require('@angular/​core');35const propMetadata = parsePropMetadataParserInput({36 props: {37 },38});39console.log(propMetadata);40{ myProp: [PropMetadata] }41const { parsePropMetadataParserInput } = require('ng-mocks');42const { PropMetadata }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parsePropMetadataParserInput } from 'ng-mocks';2import { Component } from '@angular/​core';3@Component({4})5export class TestComponent {6 constructor() {7 const input = `@Input() test: string;`;8 const component = parsePropMetadataParserInput(input);9 console.log(component);10 }11}12import { parsePropMetadataParserInput } from 'ng-mocks';13import { Component } from '@angular/​core';14@Component({15})16export class TestComponent {17 constructor() {18 const input = `@Input() test: string;`;19 const component = parsePropMetadataParserInput(input);20 console.log(component);21 }22}23import { parsePropMetadataParserInput } from 'ng-mocks';24import { Component } from '@angular/​core';25@Component({26})27export class TestComponent {28 constructor() {29 const input = `@Input() test: string;`;30 const component = parsePropMetadataParserInput(input);31 console.log(component);32 }33}34import { parsePropMetadataParserInput } from 'ng-mocks';35import { Component } from '@angular/​core';36@Component({37})38export class TestComponent {39 constructor() {40 const input = `@Input() test: string;`;41 const component = parsePropMetadataParserInput(input);42 console.log(component);43 }44}45import { parsePropMetadataParserInput } from 'ng-mocks';46import { Component } from '@angular/​core';47@Component({48})49export class TestComponent {

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Continuous delivery and continuous deployment offer testers opportunities for growth

Development practices are constantly changing and as testers, we need to embrace change. One of the changes that we can experience is the move from monthly or quarterly releases to continuous delivery or continuous deployment. This move to continuous delivery or deployment offers testers the chance to learn new skills.

Test Managers in Agile &#8211; Creating the Right Culture for Your SQA Team

I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.

How To Write End-To-End Tests Using Cypress App Actions

When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.

A Complete Guide To CSS Grid

Ever since the Internet was invented, web developers have searched for the most efficient ways to display content on web browsers.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful