Skip to content

Commit

Permalink
refactor: svgNodeFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Feb 2, 2024
1 parent 7ee90cc commit 1b4e454
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 7 additions & 6 deletions projects/cdk/constants/svg-node-filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Filtering SVGElements for TreeWalker
// Filter must be a function in IE, other modern browsers are compliant to this format
export const svgNodeFilter: NodeFilter = ((node: Node) =>
'ownerSVGElement' in node
? NodeFilter.FILTER_REJECT
: NodeFilter.FILTER_ACCEPT) as any;
export const svgNodeFilter: Exclude<NodeFilter, (node: Node) => number> = {
acceptNode(node: Node): number {
return 'ownerSVGElement' in node
? NodeFilter.FILTER_REJECT
: NodeFilter.FILTER_ACCEPT;
},
};
13 changes: 6 additions & 7 deletions projects/cdk/constants/test/svg-node-filter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {svgNodeFilter} from '@taiga-ui/cdk';

// TODO: 3.0 rewrite tests after IE removing
describe('SvgNodeFilter', () => {
it('child SVG', () => {
const node: Node = {ownerSVGElement: null} as unknown as Node;

expect((svgNodeFilter as any)(node)).toBe(NodeFilter.FILTER_REJECT);
expect(svgNodeFilter.acceptNode({ownerSVGElement: null} as unknown as Node)).toBe(
NodeFilter.FILTER_REJECT,
);
});

it('not child SVG', () => {
const node: Node = {} as unknown as Node;

expect((svgNodeFilter as any)(node)).toBe(NodeFilter.FILTER_ACCEPT);
expect(svgNodeFilter.acceptNode({} as unknown as Node)).toBe(
NodeFilter.FILTER_ACCEPT,
);
});
});

0 comments on commit 1b4e454

Please sign in to comment.