packages/enzyme/src/selectors.js
function nodeMatchesToken(node, token, root) {
  if (node === null || typeof node === 'string') {
    return false;
  }
  switch (token.type) {
    /**
     * Match every node
     * @example '*' matches every node
     */
    case UNIVERSAL_SELECTOR:
      return true;
    /**
     * Match against the className prop
     * @example '.active' matches <div className='active' />
     */
    case CLASS_SELECTOR:
      return hasClassName(node, token.name);
    /**
     * Simple type matching
     * @example 'div' matches <div />
     */
    case TYPE_SELECTOR:
      return nodeHasType(node, token.name);
    /**
     * Match against the `id` prop
     * @example '#nav' matches <ul id="nav" />
     */
    case ID_SELECTOR:
      return nodeHasId(node, token.name);
    /**
     * Matches if an attribute is present, regardless
     * of its value
     * @example '[disabled]' matches <a disabled />
     */
    case ATTRIBUTE_PRESENCE:
      return matchAttributeSelector(node, token);
    /**
     * Matches if an attribute is present with the
     * provided value
     * @example '[data-foo=foo]' matches <div data-foo="foo" />
     */
    case ATTRIBUTE_VALUE:
      return matchAttributeSelector(node, token);
    case PSEUDO_ELEMENT:
    case PSEUDO_CLASS:
      return matchPseudoSelector(node, token, root);
    default:
      throw new Error(`Unknown token type: ${token.type}`);
  }
}
function nodeMatchesToken(node, token, root) {
  if (node === null || typeof node === 'string') {
    return false;
  }
  switch (token.type) {
    /**
     * Match every node
     * @example '*' matches every node
     */
    case UNIVERSAL_SELECTOR:
      return true;
    /**
     * Match against the className prop
     * @example '.active' matches <div className='active' />
     */
    case CLASS_SELECTOR:
      return hasClassName(node, token.name);
    /**
     * Simple type matching
     * @example 'div' matches <div />
     */
    case TYPE_SELECTOR:
      return nodeHasType(node, token.name);
    /**
     * Match against the `id` prop
     * @example '#nav' matches <ul id="nav" />
     */
    case ID_SELECTOR:
      return nodeHasId(node, token.name);
    /**
     * Matches if an attribute is present, regardless
     * of its value
     * @example '[disabled]' matches <a disabled />
     */
    case ATTRIBUTE_PRESENCE:
      return matchAttributeSelector(node, token);
    /**
     * Matches if an attribute is present with the
     * provided value
     * @example '[data-foo=foo]' matches <div data-foo="foo" />
     */
    case ATTRIBUTE_VALUE:
      return matchAttributeSelector(node, token);
    case PSEUDO_ELEMENT:
    case PSEUDO_CLASS:
      return matchPseudoSelector(node, token, root);
    default:
      throw new Error(`Unknown token type: ${token.type}`);
  }
}
function nodeMatchesToken ( node , token , root ) { if ( node === null || typeof node === 'string' ) { return false ; } switch ( token . type ) { /**
     * Match every node
     * @example '*' matches every node
     */ case UNIVERSAL_SELECTOR : return true ; /**
     * Match against the className prop
     * @example '.active' matches <div className='active' />
     */ case CLASS_SELECTOR : return hasClassName ( node , token . name ) ; /**
     * Simple type matching
     * @example 'div' matches <div />
     */ case TYPE_SELECTOR : return nodeHasType ( node , token . name ) ; /**
     * Match against the `id` prop
     * @example '#nav' matches <ul id="nav" />
     */ case ID_SELECTOR : return nodeHasId ( node , token . name ) ; /**
     * Matches if an attribute is present, regardless
     * of its value
     * @example '[disabled]' matches <a disabled />
     */ case ATTRIBUTE_PRESENCE : return matchAttributeSelector ( node , token ) ; /**
     * Matches if an attribute is present with the
     * provided value
     * @example '[data-foo=foo]' matches <div data-foo="foo" />
     */ case ATTRIBUTE_VALUE : return matchAttributeSelector ( node , token ) ; case PSEUDO_ELEMENT : case PSEUDO_CLASS : return matchPseudoSelector ( node , token , root ) ; default : throw new Error ( ` ${ token . type } ` ) ; } }
Takes a node and a token and determines if the node
matches the predicate defined by the token.
@param {Node} node
@param {Token} token
Takes a node and a token and determines if the node matches the predicate defined by the token .