My application is using astrouxds web components and I am getting a warning in my tests that I would like to fix. I'm also not sure how to assert on a value in the web component.
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Unknown custom element: <rux-toggle> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> <App>
<Root>
I have setup an example application here. It uses rux-toggle
as an example.
The application has a simple template and script in a .vue
file.
<template>
<div id="app">
<rux-toggle
id="app-toggle"
:checked="toggle"
@click.prevent="toggle = !toggle"></rux-toggle> {{ toggle }}
</div>
</template>
<script>
export default {
name: 'App',
computed: {
toggle: {
get() {
return this.$store.state.toggle
},
set(value) {
this.$store.commit('setToggle', value)
}
}
}
}
</script>
The test uses mount
to create a wrapper and test that the web component is checked.
import Vuex from 'vuex';
import {createLocalVue, mount} from '@vue/test-utils';
import storeConfig from '@/store'
import App from '@/App'
describe("App", () => {
let localVue;
let store;
let wrapper;
beforeEach(() => {
localVue = createLocalVue();
localVue.use(Vuex);
store = new Vuex.Store(storeConfig);
wrapper = mount(App, {store, localVue});
});
it("test toggle default", () => {
const result = wrapper.find('#app-toggle').checked;
expect(result).toEqual(true);
})
})
The test fails with:
Error: expect(received).toEqual(expected) // deep equality
Expected: true
Received: undefined
I'm not exactly sure how to get the checked
value of the web component to do the assertion correctly.
Things I have tried
- Switched from shallowMount to mount
- Register globally using Vue.component(rux-toggle, RuxToggle)
- Added
Vue.config.productionTip = false
to jest setup