Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Conversation

JessicaSachs
Copy link
Contributor

@JessicaSachs JessicaSachs commented Jul 18, 2020

The typings here are really bad, but this should solve scopedSlots, slots, etc. We also get stubbing for free :-)

Likely we can also remove the plugin installation code.

This still needs a scopedSlot test to exercise that it's working.

closes #364

  • slots
  • scopedSlots

@JessicaSachs
Copy link
Contributor Author

JessicaSachs commented Jul 18, 2020

A lot of issues covered up by some silent error handlers: unregistered components + mounting options using "data" as object literals instead of functions were the big ones.

I added localVue instead of the global Vue so that test state for plugins is cleared between specs. Some of the specs were broken and throwing console errors, but it wasn't apparent until fixing some of the underlying issues.

We have a lot of work to do regarding typing, but at least the API will look a bit more like Native Vue 😸

}
beforeEach(mountCallback({ template, data }, { extensions }))

it('registers global 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.

This is not a feature we should offer because it pollutes Vue state

@bahmutov
Copy link
Contributor

The failing test fails locally with command

npx cypress run --spec cypress/component/basic/mixins/spec.js

  Mixins
    Global mixin
      1) calls mixin "created" method
    local to test
      2) is created


  0 passing (5s)
  2 failing

  1) Mixins
       Global mixin
         calls mixin "created" method:
     AssertionError: expected stub to have been called exactly once, but it was called twice

    The following calls were made:

    stub() at getRet (http://localhost:57166/__cypress/runner/cypress_runner.js:153773:20)
    stub() at getRet (http://localhost:57166/__cypress/runner/cypress_runner.js:153773:20)
      at Context.eval (http://localhost:57166/__cypress/tests?p=cypress/component/basic/mixins/spec.js:454:43)

  2) Mixins
       local to test
         is created:
     AssertionError: Timed out retrying: expected created to have been called exactly once, but it was called twice

    The following calls were made:

    created() at VueComponent.created (http://localhost:57166/__cypress/runner/cypress_runner.js:139372:26)
    created() at VueComponent.created (http://localhost:57166/__cypress/runner/cypress_runner.js:139372:26)
      at Context.eval (http://localhost:57166/__cypress/tests?p=cypress/component/basic/mixins/spec.js:478:26)

const component = { template, data }
const component = {
template,
data() {
Copy link
Contributor

Choose a reason for hiding this comment

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

so during the test, what if we check the .data property and if it is an object, automatically make it into a function? Otherwise, this is a breaking change.

Copy link
Contributor

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

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

It is all good, I am worried about data: {} to data: () => {} change, I think we could make it convenient and transform it on the fly during mount

@JessicaSachs
Copy link
Contributor Author

JessicaSachs commented Jul 19, 2020

I know this is a breaking change, but it was a bug that was flying under the radar because we weren't failing the tests due to Vue runtime errors. If you try to mount a component with data: {} it throws an error in the Vue runtime... so you shouldn't pass tests with data: {}.

https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function

Testing a Root Vue instance is separate from testing a Vue Component.

I don't want to add it as a convenience because it has a very specific meaning for Vue components.

@JessicaSachs
Copy link
Contributor Author

Thank you for getting this passing :-)

@JessicaSachs
Copy link
Contributor Author

Weird, it seems that there's issues with the yarn registry.

@JessicaSachs JessicaSachs merged commit abb95e0 into master Jul 20, 2020
@bahmutov
Copy link
Contributor

🎉 This PR is included in version 3.4.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

JessicaSachs added a commit to cypress-io/cypress that referenced this pull request Sep 29, 2020
…malizaiton (cypress-io/cypress-vue-unit-test#365)

* Use Vue Test Utils to manage options like scoped slots and option normalization

* using createLocalVue to ensure global Vue namespace doesn't bleed over

* fix: spec was demonstrating using data as an object, which is a bug in components. It was being covered up by rendering the component as the Root Vue Component

* chore: cleaning up spec

* fix: data should be a function, i18n plugin was throwing error

* fix: plugins not passing options through. i18n spec artifically slow

* Update src/index.ts

* fix: ...localVue => localVue

* update mixins test

* enable slot AppInput spec

* add full slots and scopedSlots test

* Update src/index.ts

Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show how to pass slots to the component while mounting it
2 participants