Git Product home page Git Product logo

Comments (3)

justin-schroeder avatar justin-schroeder commented on May 26, 2024 1

We use vitest ourselves, checkout any of our tests for examples on how to do this: https://github.com/formkit/formkit/tree/master/packages/vue/__tests__/inputs

from formkit.

glennovische avatar glennovische commented on May 26, 2024

@justin-schroeder Thanks for the response, I have looked into the tests as an example and I don't get it get it working.

I used the import { FormKit } from '@formkit/vue';

this imports the definition:

The root FormKit component.
@public
export declare const FormKit: DefineComponent<    { ..... etc

In the formkit test the formkit definition is:

 The root FormKit component. Use it to craft all inputs and structure of your forms. For example:
 
  vue
  <FormKit
   type="text"
  label="Name"
   help="Please enter your name"
   validation="required|length:2"
  />
 
 
  @public
export const formkitComponent = defineComponent(setup as any, {
  props: runtimeProps as any,
  inheritAttrs: false,
}) as FormKitComponent
....

In my vitest I want to create a wrapper like:

  wrapper = mount(Pincode, {
      global: {
        components: {
          PrevNextButtons: PrevNextButtons,
          FormKit,
        },
        plugins: [
          createTestingPinia({
            createSpy: vitest.fn,
          }),
        ],
      },
    });

    console.log(wrapper.html());
I cant defineProps or assign props to Formkit

Any Ideas?

from formkit.

justin-schroeder avatar justin-schroeder commented on May 26, 2024

You need to register the FormKit plugin in your test. For example:

import { plugin, defaultConfig } from '@formkit/vue'
describe('some formkit inputs', () => {
  it('can render a text input', () => {
    const wrapper = mount(FormKit, {
      props: {
        type: 'text',
        value: 133,
      },
      {
        global: {
         plugins: [[plugin, defaultConfig]],
        }
      },
    })
    expect(wrapper.find('input').exists()).toBe(true)
  })
})

Of course you could render at template component with pinia or other plugins too.

from formkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.