Skip to content

Bug: findAll returns parent node in result array #1233

Closed
@twoBoots

Description

@twoBoots

Describe the bug
findAll returns the parent node in the result set if it matches the selector when chained from get

To Reproduce

ParentComponent.vue

<template>
  <div class="parent">
    <div>child</div>
    <div>child</div>
    <div>child</div>
  </div>
</template>

ParentComponent.spec.js

import { mount } from '@vue/test-utils';

import ParentComponent from '../ParentComponent';

describe('parent', () => {
  test('finds 3 children', () => {
    const wrapper = mount(ParentComponent);

    const parent = wrapper.get('.parent');

    expect(parent.findAll('div').length).toBe(3);
  });
});

result

parent
    ✕ finds 3 children (21 ms)

  ● parent › finds 3 children

    expect(received).toBe(expected) // Object.is equality

    Expected: 3
    Received: 4

Expected behavior
findAll returns only the 3 child nodes in the result array. This is the behaviour of vue-test-utils@1

Related information:

  • @vue/test-utils version: 2.0.0-rc.18
  • Vue version: 3.2.26
  • node version: 16.13.1
  • npm (or yarn) version: npm@8.1.2

Additional context
I'm aware of the open PR reworking find and findAll, as well as a few mentions in other issues relating to findAll of a contributor currently working on changes to findAll. Maybe the open PR or the work in progress fixes this, but I thought it was worth documenting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions