question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

findAllVNodes doesn't look through children

See original GitHub issue

Hello again! It seems for my setup that .find() doesn’t find any child nodes and therefore only looks at the parent node, making .find() the equivalent of .hasClass() (when used with a class selector). When used with an ID, it gives the error

 TypeError: node.elm.getAttribute is not a function

Also, in vNode.js, why is there a check for nodeName === '#text' (findById, line 32)?

The template of my component:

<template>
  <transition name="modal">
    <div class="modal-mask" @click="hideModal" transition="modal">
      <div class="modal-dialog" @click.stop>
        <div class="modal-header">
            <a class="btn close" @click="hideModal">
                <i class="icon-cross color-darkest-gray large"></i>
            </a>
        </div>

        <div class="modal-body">
            <slot name="body">
                <p>Default modal content goes here.</p>
            </slot>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import { mapActions } from 'vuex';

export default {
    name: 'modal',
    methods: {
      ...mapActions('Modals', [
        'hideModal'
      ])
    }
}
</script>

And when running

import { mount } from 'avoriaz';
import { expect } from 'chai';
import Modal from '../src/components/Modal.vue';

describe('Modal.vue', () => { 
  it('renders a div element with class modal-mask', () => {
    const modal = mount(Modal);

    expect(modal.is('div')).to.equal(true);
    expect(modal.hasClass('modal-mask')).to.equal(true); // Here we can see the component considers this to be its root node
  });

  it('renders a div element with class modal-mask', () => {
    const modal = mount(Modal);
    const mask = modal.find('.modal-mask')[0]; // Finds .modal-mask

    expect(mask.is('div')).to.equal(true);
  });

  it('renders a div element with class modal-dialog', () => {
    const modal = mount(Modal);
    const dialog = modal.find('.modal-dialog')[0]; 
    // .find() returns empty array, dialog equals undefined at this point
    // Same happens for any child node

    expect(dialog.is('div')).to.equal(true);
  });
});

Should I try and replicate this in a fiddle?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andreasvirkuscommented, Jan 26, 2017

Cheers, the fix works fine!

1reaction
eddyerburghcommented, Jan 25, 2017

Hey, so I’ve just got round to having a look. The vNode tree is different for transitions, and I haven’t tested for them. Tomorrow I’m going to change how the vNode search works to account for transitions and scopes.

In the meantime - here’s one way to test the div is being rendered:

  it('renders a div element with class modal-dialog', () => {
    const modal = mount(Modal);
    console.log(modal);
    const modalDialog = modal.element.querySelector('.modal-dialog');
    expect(modalDialog.tagName).to.equal('DIV');
  });
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do i find all nodes without children (starting from non-root ...
Show activity on this post. I think nonRootNodeWithChildr %>% html_nodes(xpath = ".//*[not(descendant::*)]"). could be what i was looking for.
Read more >
Node.childNodes - Web APIs - MDN Web Docs
Child nodes include elements, text and comments. ... The items in the collection of nodes are objects, not strings. To get data from...
Read more >
Print all nodes that don't have sibling - GeeksforGeeks
Given a Binary Tree, print all nodes that don't have a sibling (a sibling is a node that has same parent. In a...
Read more >
.children() | jQuery API Documentation
children () method allows us to search through the children of these elements in the DOM tree and construct a new jQuery object...
Read more >
findAll | Plugin API - Figma
findAll. Searches this entire subtree (this node's children, its children's children, etc). Returns all nodes for which callback returns true. Supported On:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found