Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing props being passed to child components on mount #161

Open
d1820 opened this issue Oct 21, 2017 · 2 comments
Open

Testing props being passed to child components on mount #161

d1820 opened this issue Oct 21, 2017 · 2 comments

Comments

@d1820
Copy link

d1820 commented Oct 21, 2017

I have a parent component where a placeholder is set as a prop. this prop is passed into a child component that has an input field. when i try and write a test to find the input adn check the rendered placeholder property its always undefined. i can find the wrapper but none of the props are set on the input component. based on #93 can i assume this functionality does not exist and there is no way to accomplish this?

PARENT

<template>
    <div >
        <div class="control-groups">
            <span>{{placeholderDisplayText}}</span>
            <gabaseinput v-model="inputModel" 
            :placeholderDisplayText="placeholderDisplayText">
            </ga-baseinput>
        </div>
    </div>
</template>
props: [ showAsterix: {
            type: Boolean,
            required: false,
            default: false
        },
        placeholder: {
            type: String,
            required: false
        },]
computed: {
        placeholderDisplayText: function() {
            return `${this.placeholder}${this.showAsterix ? ' *' : ''}`;
        }
    },

CHILD

<template>
    <div class="control-group" >
        <input type="text" class="ga-control-text" @input="updateValue" 
            :value="value" 
            :placeholder="placeholderDisplayText" : />
    </div>
</template>

props: [
placeholderDisplayText: {
            type: String,
            required: true
        }]

TEST

Before:
const instance = Vue.extend();
wrapper = mount(textbox, {
            instance
        });

Test:
wrapper.setProps({
                placeholder: 'test',
                showAsterix: true
            });
            assert.equal((wrapper.vm).placeholderDisplayText, 'test *'); //SUCCESS
            const input = wrapper.first('input');
            console.log(input.data());
            expect(input.getAttribute('placeholder')).to.equal('test *'); //FAIL = UNDEFINED for value

wrapper.html()
<div ><div ><span>test *</span> <div ><input type="text" placeholder="undefined"> <label> <!----></label> <!----> <!----></div></div></div>

Can we not test html of parent child components?

If not is there an ETA on getting this functionality.

Any help would be great.. spent 4 hours on this already trying different things

@eddyerburgh
Copy link
Owner

eddyerburgh commented Oct 22, 2017

Hey, this is actually a big issue right now for vue-test-utils too. I believe this has to do with JSDOM (are you testing with JSDOM?) implementation of DOM props vs attributes.

I'm going to try and really dig into this issue this week and will update you when I find a solution.

@d1820
Copy link
Author

d1820 commented Oct 22, 2017

Yes using JSDOM.. Thanks for looking into it.. I would but with my current tight deadlines, dont have the bandwidth...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants