Skip to content
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

Improve passing text to slots #274

Merged
merged 14 commits into from
Dec 19, 2017
Merged

Improve passing text to slots #274

merged 14 commits into from
Dec 19, 2017

Conversation

38elements
Copy link
Contributor

@38elements 38elements commented Dec 17, 2017

This is related to #244 .

The text works below.

const wrapper1 = mount(ComponentWithSlots, { slots: { default: '1{{ foo }}2' )
const wrapper2 = mount(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}<p>2</p>' )
const wrapper3 = mount(ComponentWithSlots, { slots: { default: '<p>1</p>{{ foo }}' )
const wrapper4 = mount(ComponentWithSlots, { slots: { default: '123' )
const wrapper5 = mount(ComponentWithSlots, { slots: { default: '1<p>2</p>{{ foo }}3' )
const wrapper6 = mount(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
const wrapper7 = mount(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})

if (typeof slotValue === 'string') {
if (!compileToFunctions) {
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined')
}
if (slotValue.trim()[0] === '<') {
const domParser = new window.DOMParser()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOMParser isn't supported in phantomJs, so we need an alternative that will work in phantom

Copy link
Contributor Author

@38elements 38elements Dec 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing.
Is there a choice not to support PhantomJS ?
IMHO, I think it is better to use Puppeteer.
It is better to introduce Puppeteer at document.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of users still use phantom. We could throw an error, or a warning that phantom doesn't support markup in slots, and handle it gracefully

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reply.
I will look for other ways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the error message to—option.slots does not support strings PhantomJS. Please use Puppeteer, or pass a component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry.
I did not notice your comment.
I fixed the error message.

@38elements
Copy link
Contributor Author

I changed this.
This throws error when the UserAgent is PhantomJS.

})

afterEach(() => {
/* eslint-disable */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm mistakenm you can just add // eslint-disable-line to the line, instead of 2 comments. Even better, you can add //eslint-disable-line name-of-rule to only disable eslint for the rule which is failing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing out.
I fixed it.

@38elements
Copy link
Contributor Author

I am sorry.
There were a few mistakes in document.

@38elements
Copy link
Contributor Author

I am sorry.
There is a bug.

<template>
  <div class="container" @click='change'>
    <header>
      <slot name="header"></slot>
    </header>
    <main>
      <slot></slot>
    </main>
    <footer>
      <slot name="footer"></slot>
    </footer>
  </div>
</template>

<script>
  export default {
    name: 'component-with-slots',
    data () {
      return {
        'foo': 'bar'
      }
    },
    methods: {
      change () {
        this.foo = 'baz'
      }
    }
  }
</script>
    const wrapper5 = mount(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
    wrapper5.find('.container').trigger('click')
    expect(wrapper5.find('main').html()).to.equal('<main>1baz2</main>')
   // => <main>undefined</main>

@38elements 38elements closed this Dec 17, 2017
@38elements 38elements reopened this Dec 18, 2017
@38elements 38elements closed this Dec 18, 2017
@38elements 38elements reopened this Dec 18, 2017
@38elements
Copy link
Contributor Author

I think it is resolved.

if (typeof slotValue === 'string') {
if (!compileToFunctions) {
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined')
}
if (slotValue.trim()[0] === '<') {
if (window.navigator.userAgent.match(/PhantomJS/i)) {
throwError('option.slots does not support strings PhantomJS. Please use Puppeteer, or pass a component')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option.slots does not support strings PhantomJS. Please use Puppeteer, or pass a component

to

option.slots does not support strings in PhantomJS. Please use Puppeteer, or pass a component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it.

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

Successfully merging this pull request may close these issues.

2 participants