diff --git a/AngularNoNgAttributesSnapshotSerializer.js b/AngularNoNgAttributesSnapshotSerializer.js index 5a713f6f0f..ed4b66aea7 100644 --- a/AngularNoNgAttributesSnapshotSerializer.js +++ b/AngularNoNgAttributesSnapshotSerializer.js @@ -4,26 +4,22 @@ const jestDOMElementSerializer = require('pretty-format').plugins.DOMElement; const attributesToRemovePatterns = ['ng-reflect', '_nghost', '_ngcontent', 'ng-version']; +const hasAttributesToRemove = (attribute) => + attributesToRemovePatterns + .some(removePattern => attribute.name.startsWith(removePattern)); + const serialize = (node, ...rest) => { const nodeCopy = node.cloneNode(true); Object.values(nodeCopy.attributes) - .map(attribute => attribute.name) - .filter(attributeName => - attributesToRemovePatterns - .some(removeAttributePattern => attributeName.startsWith(removeAttributePattern)) - ) - .forEach(attributeNameToRemove => nodeCopy.attributes.removeNamedItem(attributeNameToRemove)); + .filter(hasAttributesToRemove) + .forEach(attribute => nodeCopy.attributes.removeNamedItem(attribute.name)); return jestDOMElementSerializer.serialize(nodeCopy, ...rest); }; const serializeTestFn = (val) => { return val.attributes !== undefined && Object.values(val.attributes) - .map(attribute => attribute.name) - .some(attributeName => - attributesToRemovePatterns - .some(remotePattern => attributeName.startsWith(remotePattern)) - ) + .some(hasAttributesToRemove) }; const test = val => jestDOMElementSerializer.test(val) && serializeTestFn(val); diff --git a/README.md b/README.md index 77e12e2fe5..2a9b53087a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -AngularSnapshotSerializer# jest-preset-angular +# jest-preset-angular [![CircleCI Build Status](https://circleci.com/gh/thymikee/jest-preset-angular.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/thymikee/jest-preset-angular) [![NPM version](https://img.shields.io/npm/v/jest-preset-angular.svg)](https://www.npmjs.com/package/jest-preset-angular) [![Greenkeeper badge](https://badges.greenkeeper.io/thymikee/jest-preset-angular.svg)](https://greenkeeper.io/) @@ -69,7 +69,6 @@ module.exports = { }, transformIgnorePatterns: ['node_modules/(?!@ngrx)'], snapshotSerializers: [ - 'jest-preset-angular/AngularNoNgAttributesSnapshotSerializer.js', 'jest-preset-angular/AngularSnapshotSerializer.js', 'jest-preset-angular/HTMLCommentSerializer.js', ],