Skip to content

vue-class-component use causes html() to return empty html comment #73

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

Closed
ghost opened this issue Oct 3, 2017 · 24 comments
Closed

vue-class-component use causes html() to return empty html comment #73

ghost opened this issue Oct 3, 2017 · 24 comments
Labels

Comments

@ghost
Copy link

ghost commented Oct 3, 2017

Hello,

I noticed that my single file component which uses Component from vue-class-component is returning an empty html comment ('<!---->') when I print wrapper.html().

Component:

<template>
  <div id="test">
    Test
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';

@Component({})

export default class Test extends Vue {
}
</script>

Mounting in test file:
const wrapper = mount(Test);

When not using vue-test-utils, I see the same problem of the empty html comment being returned in vm.$el when I mount the component like so: vm = new Vue(Test).$mount() However I get the expected vm.$el content when I mount the component like this instead:

const vm = new Test();
vm.$mount()

Which I saw in this issue vuejs/vue-class-component#75

Not sure if this issue should be filed to vue-class-component instead.

Thanks in advance,
Kevin

@eddyerburgh eddyerburgh added the bug label Oct 4, 2017
@ktsn
Copy link
Member

ktsn commented Oct 6, 2017

This looks because mount does not support extended Vue constructor that generated with Vue.extend yet? vue-class-component convert the decorated class to the returned value of Vue.extend.

I just confirmed this happens if I use Vue.extend directly.

@eddyerburgh
Copy link
Member

eddyerburgh commented Oct 18, 2017

Try mounting the component with clone set to false:

const wrapper = mount(Test, {
  clone: false
})

vue-test-utils clones components by default so that it can stub them without affecting the base component object.

@ghost
Copy link
Author

ghost commented Oct 19, 2017

Hey @eddyerburgh, thanks for the suggestion. Unfortunately wrapper.html() is still undefined even with setting clone to false. And just to clarify, I'm running the latest version, v1.0.0-beta.2

@eddyerburgh
Copy link
Member

1.0.0-beta.3 has support for extended components. Can you try with the new version and see if it fixes your issue

@berniezajac
Copy link

Fixed it for me, @eddyerburgh - many thanks!

@ghost
Copy link
Author

ghost commented Oct 23, 2017

Fixed it for me too, thanks all!

@ghost ghost closed this as completed Oct 23, 2017
@ghost ghost reopened this Jan 3, 2018
@ghost
Copy link
Author

ghost commented Jan 3, 2018

Hey again,

I noticed this same problem happening in the latest release, beta.9. I didn't notice this in beta.8.

Could anyone take a look?
Thanks

@74sharlock
Copy link

same problem in beta.9:

let wrapper = mount({
  template: `<div>1<tester></tester></div>`,
  components: {
    tester: {
      template: `<div class="tester">test</div>`
    }
  }
});

console.log(wrapper.html());
// will return:
// <div>1<!--function (a, b, c, d) { return createElement(vm, a, b, c, d, true); }--></div>

@eddyerburgh
Copy link
Member

@conkur can you post a minimal reproduction?

@74sharlock Thanks for the bug report. I believe this is a different bug. Can you create a new issue?

@74sharlock
Copy link

@eddyerburgh Thanks for reply. I've created a new issue about that in #329

@ghost
Copy link
Author

ghost commented Jan 5, 2018

@eddyerburgh Sure, the first comment on this issue contains a reproduction (the Test component). When printing wrapper.html() in beta.3 - beta.8 it prints the expected output, but in beta.9 it's undefined

@eddyerburgh
Copy link
Member

@conkur I can't reproduce this using your example. Are you able to provide a full minimal reproduction that replicates the bug?

@ghost
Copy link
Author

ghost commented Jan 23, 2018

Sure @eddyerburgh

The component:

<template>
  <div id="test">
    Test
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';

@Component({})
export default class Test extends Vue {
}
</script>

The spec:

import Test from '~/components/Test.vue';
import { shallow } from '@vue/test-utils';

describe('Test', function() {
  it('should print wrapper.html()', function() {
    // Also see this error if using mount(Test)
    this.wrapper = shallow(Test);

    // Prints `undefined`
    console.log('html: ', this.wrapper.html());
  });
});

I am using the latest version of vue-class-component (6.1.2). I tried this on beta9 and beta10 and am seeing undefined on both versions. However, beta8 printed the expected html data.

If I remove @Component({}) from the component, beta10 prints the expected html data.

@eddyerburgh
Copy link
Member

Sorry, I still can't reproduce with your example.

Can you create a repository with a failing example so that I can debug it?

@tbsvttr
Copy link

tbsvttr commented Feb 2, 2018

Same problem here with vue-class-component & vue-property-decoratorafter updating to TS 2.7.1 from 2.6.2. Wired thing is that it works sometimes and sometimes it does not. For example if I remove a @mutation (even if not used) or change its typing (to a more correct one!) toe .html() of the wrapper becomes empty?!

@eddyerburgh
Copy link
Member

Are you able to provide a minimal reproduction @tbsvttr ? I've tried to reproduce with TypeScript and in plain JavaScript and have been unsuccessful. Once I have a reproduction (a GitHub repository that shows the bug) I can add a fix for it 😀.

@Skwai
Copy link

Skwai commented Feb 4, 2018

Also occurring for me :(

Getting undefined on my component

@eddyerburgh
Copy link
Member

Can someone please provide a GitHub repository with a reproduction.

I've tried to reproduce this issue three times but been unable, I'd like to get this fixed but can't fix until I have an example where it's not working!

@Skwai
Copy link

Skwai commented Feb 5, 2018

I'm getting undefined on Vue components in this branch of mine (if you run yarn unit). By no means minimal. Could also be that I've screwed up the jest/vue/typescript configuration... although the typescript unit tests (not .vue) work fine...

https://github.com/Skwai/bitext/tree/typescript-vue

If there was a definitive guide to using the following together that'd be great, as I was trying to piece it together based on a bunch of other examples I found:

  • Vue
  • Vue class component
  • Vue property decorator
  • Jest
  • Typescript

The unit test:
https://github.com/Skwai/bitext/blob/a98951a08c22644c47690243153792f2ed424d69/test/AppButton.spec.ts

@Skwai
Copy link

Skwai commented Feb 6, 2018

It looks like vue-cli 3.x scaffolding seems to fix this issue. I might rebase my project off that

@tbsvttr
Copy link

tbsvttr commented Feb 6, 2018

@Skwai Do you know how vue-cli is fixing this issue?

@eddyerburgh
Copy link
Member

I still aren't able to reproduce this issue. There have been some updates that mean VueClassComponents are stubbed correctly by shallow in beta-11. This might be why your tests that were previously rendering text aren't any more.

I'm going to close this issue, as I've added tests for shallow and mount using vue-class-component. If anyone can provide a minimal reproduction of the original issue, I'll reopen and look into it.

@Skwai
Copy link

Skwai commented Feb 15, 2018

@tbsvttr It looks like it abstracts it away to a vue-cli-service which must do some "magic"

@tbsvttr
Copy link

tbsvttr commented Feb 15, 2018

@Skwai Thank you very much for the hint. I even found out what the "magic" is. vue-cli-service uses vue-jest, but I used jest-vue-preprocessor before. After I replaced the first with the latter one everything is working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants