Heim  >  Fragen und Antworten  >  Hauptteil

Textfeld-Update funktioniert im Vue-Testprogramm nicht (nur ein Scherz)

Hallo, ich bin neu im Scherz- und Unit-Testing. Ich möchte fragen, wie man die Werttexteingabe mithilfe von Vue-Testdienstprogrammen festlegt.

Bald hatte ich meine benutzerdefinierte Komponente für die Texteingabe, hier ist mein Code

<input
    v-model="local_value"
    @keyup.enter="submitToParent"
    :class="input_class"
    :id="id"
    :disabled="is_disabled"
    :maxlength="max_length"
    :placeholder="placeholder"
    :autocomplete="(is_autocomplete) ? 'on' : 'off'"
    :name="id"
    :ref="id"
  />

Das ist mein Test

it("type something on field", async () => {
        const wrapper = shallowMount(TextInput, {
            propsData: {
                id: "my_input",
            }
        })

        // find component (its work properly) and I want to try inserting some text
        const input = wrapper.findComponent({ref: "my_input"})
        input.element.value = "sample text"
        input.setValue("sample text")

        // the value still empty string (""), idk what happens with my code
        console.log(wrapper.vm.local_value)
        expect(wrapper.vm.local_value).toBe("sample text")

Bitte sagen Sie mir, ob Sie die Lösung für dieses Problem kennen. Vielen Dank für Ihre Zeit

P粉604669414P粉604669414178 Tage vor314

Antworte allen(1)Ich werde antworten

  • P粉476883986

    P粉4768839862024-03-27 00:39:21

    据我所知, setValue 是异步的,所以你可能需要设置它 await input.setValue('示例文本')

    Antwort
    0
  • StornierenAntwort