Skip to content

Commit

Permalink
feat(test): add hasNextSibling() predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
localvoid committed May 14, 2018
1 parent cdfa1fd commit 5d10979
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/ivi-test/src/query.ts
Expand Up @@ -5,8 +5,8 @@ import {
VNodeWrapper, visitWrapped,

isElement, isElementWithClassName,
hasParent, hasDirectParent, hasChild, hasSibling, hasPrevSibling, hasFactory, hasClassName, hasKey, hasProps,
hasExactProps, hasAssignedProps, hasStyle, hasExactStyle, hasAssignedStyle, hasEventHandler, hasUnsafeHTML,
hasParent, hasDirectParent, hasChild, hasSibling, hasPrevSibling, hasNextSibling, hasFactory, hasClassName, hasKey,
hasProps, hasExactProps, hasAssignedProps, hasStyle, hasExactStyle, hasAssignedStyle, hasEventHandler, hasUnsafeHTML,
hasAutofocus, hasInputValue,
innerText,
} from "./vdom";
Expand Down Expand Up @@ -55,6 +55,11 @@ export class VNodeMatcher extends Matcher<VNodeWrapper> {
this.addPredicate((n: VNodeWrapper) => hasPrevSibling(n, matcher.match));
return this;
}

hasNextSibling(matcher: VNodeMatcher): this {
this.addPredicate((n: VNodeWrapper) => hasNextSibling(n, matcher.match));
return this;
}
}

export class VNodeElementMatcher extends Matcher<VNodeWrapper> {
Expand Down
9 changes: 9 additions & 0 deletions packages/ivi-test/src/vdom.ts
Expand Up @@ -545,6 +545,15 @@ export function hasPrevSibling(wrapper: VNodeWrapper, predicate: Predicate<VNode
return false;
}

export function hasNextSibling(wrapper: VNodeWrapper, predicate: Predicate<VNodeWrapper>): boolean {
const parent = wrapper.parent;
const next = wrapper.vnode.next;
if (next !== null) {
return predicate(new VNodeWrapper(next, parent, wrapper.context));
}
return false;
}

export function innerText(wrapper: VNodeWrapper): string {
let result = "";
visitUnwrapped(
Expand Down

0 comments on commit 5d10979

Please sign in to comment.