Situation
[vue-test-utils]: Using a string for stubs is deprecated and will be removed in the next major version.
Solution
import MessageContainer from '@/components/MessageContainer'
import { mount } from '@vue/test-utils'
const MessageDisplayMock0 = '<p data-testid="message">Hello from the db!</p>'
const MessageDisplayMock1 = {
template: '<p data-testid="message">Hello from the db!</p>'
}
const MessageDisplayMock2 = {
render(h) {
return h(
'div',
{ attrs: { 'data-testid': 'message' } },
'Hello from the db!'
)
}
}
describe('MessageContainer', () => {
it('Wraps the MessageDisplay component', () => {
const wrapper = mount(MessageContainer, {
stubs: {
MessageDisplay: MessageDisplayMock0
}
})
const message = wrapper.find('[data-testid="message"]').element.textContent
expect(message).toEqual('Hello from the db!')
})
})