UNPKG

ng-stubs

Version:

[![Build Status](https://travis-ci.org/planser/ng-stubs.svg?branch=master)](https://travis-ci.org/planser/ng-stubs)

79 lines (78 loc) 4.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSpy = exports.providesNgValueAccessor = exports.contentChildrenPropMetadataQueriesFor = exports.contentChildPropMetadataQueriesFor = exports.outputPropMetadataBindingsFor = exports.inputPropMetadataBindingsFor = exports.outputAnnotationsBindingsFor = exports.inputAnnotationsBindingsFor = exports.annotationBindingsFor = exports.propMetadataQueriesFor = exports.propMetadataBindingsFor = exports.annotationFor = exports.spyOnMethod = exports.isMethod = exports.isComponent = exports.isDirective = void 0; var core_1 = require("@angular/core"); var forms_1 = require("@angular/forms"); function isDirective(a) { return a.ngMetadataName == "Directive"; } exports.isDirective = isDirective; function isComponent(a) { return a.ngMetadataName == "Component"; } exports.isComponent = isComponent; function isMethod(target, property) { var descriptor = Object.getOwnPropertyDescriptor(target, property); return descriptor.hasOwnProperty("get") == false && descriptor.hasOwnProperty("set") == false; } exports.isMethod = isMethod; function spyOnMethod(target, property) { target[property] = createSpy(); } exports.spyOnMethod = spyOnMethod; function annotationFor(component) { return new core_1.ɵReflectionCapabilities().annotations(component).find(function (a) { return isDirective(a) || isComponent(a); }); } exports.annotationFor = annotationFor; function propMetadataBindingsFor(component, ngMetadataName) { var metaData = new core_1.ɵReflectionCapabilities().propMetadata(component); return Object.keys(metaData) .map(function (key) { return [key, metaData[key].find(function (e) { return e.ngMetadataName == ngMetadataName; })]; }) .filter(function (e) { return e[1] != null; }) .map(function (e) { return ({ propName: e[0], templateName: e[1].bindingPropertyName ? e[1].bindingPropertyName : e[0] }); }); } exports.propMetadataBindingsFor = propMetadataBindingsFor; function propMetadataQueriesFor(component, ngMetadataName) { var metaData = new core_1.ɵReflectionCapabilities().propMetadata(component); return Object.keys(metaData) .map(function (key) { return [key, metaData[key].find(function (e) { return e.ngMetadataName == ngMetadataName; })]; }) .filter(function (e) { return e[1] != null; }) .map(function (e) { return ({ propName: e[0], query: e[1] }); }); } exports.propMetadataQueriesFor = propMetadataQueriesFor; function annotationBindingsFor(component, annotation, annotationKey) { return annotation == null ? [] : (annotation[annotationKey] ? annotation[annotationKey] : []); } exports.annotationBindingsFor = annotationBindingsFor; function inputAnnotationsBindingsFor(component, annotation) { return annotationBindingsFor(component, annotation, "inputs"); } exports.inputAnnotationsBindingsFor = inputAnnotationsBindingsFor; function outputAnnotationsBindingsFor(component, annotation) { return annotationBindingsFor(component, annotation, "outputs"); } exports.outputAnnotationsBindingsFor = outputAnnotationsBindingsFor; function inputPropMetadataBindingsFor(component) { return propMetadataBindingsFor(component, "Input"); } exports.inputPropMetadataBindingsFor = inputPropMetadataBindingsFor; function outputPropMetadataBindingsFor(component) { return propMetadataBindingsFor(component, "Output"); } exports.outputPropMetadataBindingsFor = outputPropMetadataBindingsFor; function contentChildPropMetadataQueriesFor(component) { return propMetadataQueriesFor(component, "ContentChild"); } exports.contentChildPropMetadataQueriesFor = contentChildPropMetadataQueriesFor; function contentChildrenPropMetadataQueriesFor(component) { return propMetadataQueriesFor(component, "ContentChildren"); } exports.contentChildrenPropMetadataQueriesFor = contentChildrenPropMetadataQueriesFor; function providesNgValueAccessor(annotation) { return annotation.providers ? annotation.providers.find(function (p) { return p.provide === forms_1.NG_VALUE_ACCESSOR; }) != null : false; } exports.providesNgValueAccessor = providesNgValueAccessor; function createSpy() { return window.ngStubsCreateSpy ? window.ngStubsCreateSpy() : jasmine.createSpy(); } exports.createSpy = createSpy;