Closed lambdalisue closed 6 years ago
@lambdalisue please see similar feature request here #410
Actually, I've read that and https://github.com/vuejs/vue-test-utils/issues/458 before making this issue.
Yes, it's similar but the point is stubs
remove attributes so it does not suit my purpose.
Am I wrong?
as a workaround you can try to use generateStubs
: https://github.com/vuejs/vue-test-utils/issues/410#issuecomment-375894160
I hope that I'll be have enough time at current holidays and send PR to solve the issue.
@ilyaztsv I've tried that one several days ago and it did not work in my environment so I ended up. Today I fixed that function (commented on #410) and that works perfectly. Thanks for pointing me a correct direction 👍
<!-- x-icon -->
<template>
<i class="icon">{{ face }}</i>
</template>
<script lang="ts">
export default {
name: 'IconView',
prop: ['face'],
}
<!-- x-checker -->
<template>
<div class="checker">
<x-icon @click="clicked" :face="face"/>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
import IconView from './icon.vue';
@Component({
components: {
'x-icon': IconView,
}
})
export default class CheckerView extends Vue {
checked: boolean = false;
get face(): {
return this.chekced ? 'checkbox-checked' : 'checkbox-empty';
}
clicked(): void {
this.checked = !this.checked;
}
}
</script>
With this case, stubs
way has the following issues but my way.
// XXX: Imaginally code
const checker = shallow(CheckerView, {
stubs: generateStubs(CheckerView),
});
const icon = checker.find('x-icon');
// With 'stubs', this click event cannot call 'clicked'
icon.trigger('click');
// So the follwoing fail.
expect(checker.vm.checked).toBe(true);
You can use shallow
and test the component props
:
const wrapper = shallow(TestComponent)
wrapper.find(XComponent).props()
If the stubs option doesn't work, that is a bug. The intended behavior is to always stub the component
I'd love to but as I explained above, it is not what I expected.
I'm closing this issue as it's not clear to me what the intention is.
The original issue is a feature request. We have recently changed stubs to render the component name, which I believe satisfied your use case. If you would like a different feature, please create a new issue with a proposal.
If you would like to report a bug, like you mentioned in your other components, please create an issue with a reproduction.
What problem does this feature solve?
Intro
Assume that there are two components,
<x-icon>
and<x-checkbox>
.The
<x-icon>
component is for showing a font icon given byface="..."
attributes likeAnd
<x-checkbox>
uses<x-icon>
withface
attribute likeSo the final HTML will be one of the followings (without resolving
<x-icon>
)What I would like to do
I would like to test
<x-checkbox>
component without understanding an implementation of the<x-icon>
. For example, I would like to check<x-icon face="checkbox-empty">
<x-icon face="checkbox-checked">
after<x-checkbox>
has clicked.For this purpose, I cannot use
stubs: { 'x-icon': true }
whilex-icon
is defined incomponents
attributes ofx-checkbox
component and in this case,stubs
seems ignored.stubs
creates an empty comment so I cannot check if the component isx-icon
or notstubs
removes attributes even I usesstubs: { 'x-icon': SomeThing }
so I cannot check if the component attributes ofx-icon
has correctly changedWhat does the proposed API look like?
I'm not really proposing but currently, I use a wrapper function to
localVue.config.isUnknownElement
function to allow elements incomponents
components
to prevent element resolvinglike
Is this a correct way?