/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { ɵgetDOM as getDOM } from '@angular/common'; import { ComponentFixture } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { childNodesAsList, hasClass, hasStyle, isCommentNode } from './browser_util'; /** * Jasmine matching function with Angular matchers mixed in. * * ## Example * * {@example testing/ts/matchers.ts region='toHaveText'} */ const _expect = expect; export { _expect as expect }; beforeEach(function () { jasmine.addMatchers({ toHaveText: function () { return { compare: function (actual, expectedText) { const actualText = elementText(actual); return { pass: actualText == expectedText, get message() { return 'Expected ' + actualText + ' to be equal to ' + expectedText; } }; } }; }, toHaveCssClass: function () { return { compare: buildError(false), negativeCompare: buildError(true) }; function buildError(isNot) { return function (actual, className) { return { pass: hasClass(actual, className) == !isNot, get message() { return `Expected ${actual.outerHTML} ${isNot ? 'not ' : ''}to contain the CSS class "${className}"`; } }; }; } }, toHaveCssStyle: function () { return { compare: function (actual, styles) { let allPassed; if (typeof styles === 'string') { allPassed = hasStyle(actual, styles); } else { allPassed = Object.keys(styles).length !== 0; Object.keys(styles).forEach(prop => { allPassed = allPassed && hasStyle(actual, prop, styles[prop]); }); } return { pass: allPassed, get message() { const expectedValueStr = typeof styles === 'string' ? styles : JSON.stringify(styles); return `Expected ${actual.outerHTML} ${!allPassed ? ' ' : 'not '}to contain the CSS ${typeof styles === 'string' ? 'property' : 'styles'} "${expectedValueStr}"`; } }; } }; }, toImplement: function () { return { compare: function (actualObject, expectedInterface) { const intProps = Object.keys(expectedInterface.prototype); const missedMethods = []; intProps.forEach((k) => { if (!actualObject.constructor.prototype[k]) missedMethods.push(k); }); return { pass: missedMethods.length == 0, get message() { return 'Expected ' + actualObject + ' to have the following methods: ' + missedMethods.join(', '); } }; } }; }, toContainComponent: function () { return { compare: function (actualFixture, expectedComponentType) { const failOutput = arguments[2]; const msgFn = (msg) => [msg, failOutput].filter(Boolean).join(', '); // verify correct actual type if (!(actualFixture instanceof ComponentFixture)) { return { pass: false, message: msgFn(`Expected actual to be of type \'ComponentFixture\' [actual=${actualFixture.constructor.name}]`) }; } const found = !!actualFixture.debugElement.query(By.directive(expectedComponentType)); return found ? { pass: true } : { pass: false, message: msgFn(`Expected ${expectedComponentType.name} to show`) }; } }; } }); }); function elementText(n) { const hasNodes = (n) => { const children = n.childNodes; return children && children.length > 0; }; if (n instanceof Array) { return n.map(elementText).join(''); } if (isCommentNode(n)) { return ''; } if (getDOM().isElementNode(n)) { const tagName = n.tagName; if (tagName === 'CONTENT') { return elementText(Array.prototype.slice.apply(n.getDistributedNodes())); } else if (tagName === 'SLOT') { return elementText(Array.prototype.slice.apply(n.assignedNodes())); } } if (hasShadowRoot(n)) { return elementText(childNodesAsList(n.shadowRoot)); } if (hasNodes(n)) { return elementText(childNodesAsList(n)); } return n.textContent; } function hasShadowRoot(node) { return node.shadowRoot != null && node instanceof HTMLElement; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWF0Y2hlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9wbGF0Zm9ybS1icm93c2VyL3Rlc3Rpbmcvc3JjL21hdGNoZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUdILE9BQU8sRUFBQyxPQUFPLElBQUksTUFBTSxFQUFDLE1BQU0saUJBQWlCLENBQUM7QUFFbEQsT0FBTyxFQUFDLGdCQUFnQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFDdkQsT0FBTyxFQUFDLEVBQUUsRUFBQyxNQUFNLDJCQUEyQixDQUFDO0FBRTdDLE9BQU8sRUFBQyxnQkFBZ0IsRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLGFBQWEsRUFBQyxNQUFNLGdCQUFnQixDQUFDO0FBNERuRjs7Ozs7O0dBTUc7Q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gICAgfVxuICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgIH07XG4gICAgfSxcblxuICAgIHRvSW1wbGVtZW50OiBmdW5jdGlvbigpIHtcbiAgICAgIHJldHVybiB7XG4gICAgICAgIGNvbXBhcmU6IGZ1bmN0aW9uKGFjdHVhbE9iamVjdDogYW55LCBleHBlY3RlZEludGVyZmFjZTogYW55KSB7XG4gICAgICAgICAgY29uc3QgaW50UHJvcHMgPSBPYmplY3Qua2V5cyhleHBlY3RlZEludGVyZmFjZS5wcm90b3R5cGUpO1xuXG4gICAgICAgICAgY29uc3QgbWlzc2VkTWV0aG9kczogYW55W10gPSBbXTtcbiAgICAgICAgICBpbnRQcm9wcy5mb3JFYWNoKChrKSA9PiB7XG4gICAgICAgICAgICBpZiAoIWFjdHVhbE9iamVjdC5jb25zdHJ1Y3Rvci5wcm90b3R5cGVba10pIG1pc3NlZE1ldGhvZHMucHVzaChrKTtcbiAgICAgICAgICB9KTtcblxuICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBwYXNzOiBtaXNzZWRNZXRob2RzLmxlbmd0aCA9PSAwLFxuICAgICAgICAgICAgZ2V0IG1lc3NhZ2UoKSB7XG4gICAgICAgICAgICAgIHJldHVybiAnRXhwZWN0ZWQgJyArIGFjdHVhbE9iamVjdCArXG4gICAgICAgICAgICAgICAgICAnIHRvIGhhdmUgdGhlIGZvbGxvd2luZyBtZXRob2RzOiAnICsgbWlzc2VkTWV0aG9kcy5qb2luKCcsICcpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH07XG4gICAgICAgIH1cbiAgICAgIH07XG4gICAgfSxcblxuICAgIHRvQ29udGFpbkNvbXBvbmVudDogZnVuY3Rpb24oKSB7XG4gICAgICByZXR1cm4ge1xuICAgICAgICBjb21wYXJlOiBmdW5jdGlvbihhY3R1YWxGaXh0dXJlOiBhbnksIGV4cGVjdGVkQ29tcG9uZW50VHlwZTogVHlwZTxhbnk+KSB7XG4gICAgICAgICAgY29uc3Qg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