diff --git a/packages/shared/stub-components.js b/packages/shared/stub-components.js index 6016e52f9..1b0b2e2aa 100644 --- a/packages/shared/stub-components.js +++ b/packages/shared/stub-components.js @@ -83,6 +83,13 @@ function createStubFromString ( } } +function createClassString (staticClass, dynamicClass) { + if (staticClass && dynamicClass) { + return staticClass + ' ' + dynamicClass + } + return staticClass || dynamicClass +} + function createBlankStub ( originalComponent: Component, name: string @@ -105,7 +112,11 @@ function createBlankStub ( { attrs: componentOptions.functional ? { ...context.props, - ...context.data.attrs + ...context.data.attrs, + class: createClassString( + context.data.staticClass, + context.data.class + ) } : { ...this.$props } diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index 3b40db304..507fb48a1 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -156,6 +156,22 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { expect(wrapper.html()).to.contain(' { + const TestComponent = { + template: ``, + data: () => ({ + 'classA': 'a' + }), + components: { + child: { template: '
' } + } + } + const wrapper = shallowMount(TestComponent) + expect(wrapper.html()).to.contain(' { const TestComponent = { template: ``, @@ -173,6 +189,41 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { expect(wrapper.html()).to.contain(' { + const components = { + Child: { + functional: true + } + } + const TestComponent = { + template: ``, + data: () => ({ + 'classA': 'a' + }), + components + } + const wrapper = shallowMount(TestComponent) + expect(wrapper.html()).to.contain('`, + data: () => ({ + 'classA': 'a' + }), + components + } + const wrapper2 = shallowMount(TestComponent2) + expect(wrapper2.html()).to.contain('`, + data: () => ({ + 'classA': 'a' + }), + components + } + const wrapper3 = shallowMount(TestComponent3) + expect(wrapper3.html()).to.contain(' { const TestComponent = { template: `