-
Notifications
You must be signed in to change notification settings - Fork 267
wip: shallow #21
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
wip: shallow #21
Conversation
Short and sweet. Would love to see an impl of stubs 👍 |
GJ!. Should we keep stubs to just an array of names or allow providing your own component definition as well? |
Hm, I think we should start with default stubs (that would be the MVP). We can add support for custom definitions after. Maybe not an array, but object syntax like beta? Unless there is a good use case for an array instead (?)
Makes it easy to add custom implementations if we want. Also faster to lookup O(1) if a component is stubbed than if we use an array, which is worst case O(n). |
I'd go with the object syntax too, so there's only a single way to define stubs 👍 |
{
stubs: {
componentA: true,
componentB: { template: '<div class="stub" />' },
componentC: { render: () => h('') },
}
} Like this, and we start just with Boolean? |
Looks good! I think boolean only will be enough for a public alpha. |
|
||
// must be a custom component. Stub! | ||
const name = kebabCase(args[0]['name'] || 'anonymous') | ||
return [`${name}-stub`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love how clean getting a stubbed version of the component looks like. It might get dirtier at some point, but this is a great starting point 👌
import { mount } from '../../src' | ||
|
||
describe('mounting options: shallow', () => { | ||
it('stubs everything with a single root node', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('stubs everything with a single root node', async () => { | |
it('stubs child components when rendering a single root node', () => { |
expect(wrapper.find('bar-stub').exists()).toBeTruthy() | ||
}) | ||
|
||
it('stubs everything with a single root node', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('stubs everything with a single root node', async () => { | |
it('stubs child components when rendering several root nodes', () => { |
Unfortunately I see no way to do Need some way for people to emit events from stubbed components. Common use case. Also |
I can try to see if I can make Find work with a component tomorrow. |
Sure. I have spent quite a few hours doing so and failed. Make sure you consider components with and without a single root node. |
closed in favor of #56, I will use the work done there for shallow mount |
It works! Tracking in #6.
Evan made a feature to let us have shallowMount without hacking Vue to pieces like we do in beta:
Source
Tests
Basically, you call
transformVNodeArgs
and you can override the default behavior - this is so clean.TODO:
stubs
should be easy, though (I prefer people use a test runner for this, egjest.mock
? Although this is a popular feature in beta)shallow
mounting option instead of ashallowMount
method. I seeshallow
as just one feature of VTU, not a main API. Instead of "you can mount or shallowMount" I want people to say "you mount your component. There is ashallow
mounting option, among other mounting options, you can use to test your components).I wonder instead of using a basic stub we can use a more specialized on that can emit events or something 🤔