testing-library / vue-testing-library

🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
http://testing-library.com/vue
MIT License
1.07k stars 111 forks source link

Issues with renderless components #219

Closed IpelaTech closed 3 years ago

IpelaTech commented 3 years ago

Describe the bug

When I try to test a renderless component, child components of the renderless component are not rendered.

To Reproduce Steps to reproduce the behavior:

Expected behavior

That all components are rendered and can be accessed by the getText, etc. The initial error I got was that getText could not find the text.

Screenshots The error message:

image

Related information:

Relevant code or config (if any)


  //MapboxToken.vue
 <script>
export default {
    props: { mapbox_token: Object },
    data() {
        return {
            token: ""
        };
    },
    render() {
        return this.$scopedSlots.default({
            token: this.token
        });
    },
    created() {
        console.log(this.mapbox_token);
        this.token = this.mapbox_token.token;
    }
};
</script>

//Create.vue
 <div>
        <mapbox-token :mapbox_token="map_token" v-slot="{ token }">
            <header>
                <h4 class="text-white">Schedule Callout</h4>
            </header>
        </mapbox-token>
 </div>

//Create.spec.js
import { render, fireEvent } from "@testing-library/vue";
import Create from "../../../../../resources/js/Pages/TowRequest/Create.vue";

test("increments value on click", async () => {
    // The render method returns a collection of utilities to query your component.
    const { getByText, debug } = render(Create, {
        props: {
            map_token: {
                token: "xstasd"
            }
        }
    });

    //debug();
    getByText("Schedule Callout");
});

Additional context

Is it possible that I could have missed a step. Or I'm testing the wrong way?

Thanks. Ipeleng

IpelaTech commented 3 years ago

Apologies, I thought the library would load the component and any scoped slots but it works as documented if I send a string or use the create element function.