Skip to content

Commit

Permalink
refactor(*): some points
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav.Sharikov committed Apr 28, 2019
1 parent d656546 commit 1617874
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
16 changes: 6 additions & 10 deletions AngularNoNgAttributesSnapshotSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
.filter(hasAttributesToRemove)
.forEach(attributeNameToRemove => nodeCopy.attributes.removeNamedItem(attributeNameToRemove));

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);
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)
Expand Down Expand Up @@ -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',
],
Expand Down

0 comments on commit 1617874

Please sign in to comment.