diff --git a/AngularNoNgAttributesSnapshotSerializer.js b/AngularNoNgAttributesSnapshotSerializer.js index 5a713f6f0f..b4dc11b413 100644 --- a/AngularNoNgAttributesSnapshotSerializer.js +++ b/AngularNoNgAttributesSnapshotSerializer.js @@ -4,14 +4,14 @@ 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)) - ) + .filter(hasAttributesToRemove) .forEach(attributeNameToRemove => nodeCopy.attributes.removeNamedItem(attributeNameToRemove)); return jestDOMElementSerializer.serialize(nodeCopy, ...rest); @@ -19,11 +19,7 @@ const serialize = (node, ...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', ],