import {mount} from "@vue/test-utils"; import {fieldNameDirective} from "@/fieldname"; describe('field name', () => { it('update and v-on order', async () => { const form = new FormData() const Text1 = { directives: { "field-name": fieldNameDirective(form), }, template: `
`, methods: { change2: function(val: any) { console.log("change2", val) form.set("Text1", val) } }, data() { return { } } } const wrapper = mount(Text1) const input = wrapper.find("input[type=text]") const value = "12345" await input.setValue(value) expect(form.get("Text1")).toEqual("12345"); }) it('update value in form', async () => { const form = new FormData() const BaseInput = { template: ` `, data() { return { } }, props: { label: String, value: String, } } const Text1 = { directives: { "field-name": fieldNameDirective(form), }, components: { "base-input": BaseInput, }, template: `
`, methods: { }, data() { return { Text1FieldChange: "", BaseInput1FieldChange: "" } } } const wrapper = mount(Text1) expect(form.get("Hidden1")).toEqual("hidden1value"); expect(form.get("Radio1")).toEqual("Radio1 checked value"); expect(form.get("Checkbox1")).toEqual("checkbox checked value"); expect(form.get("Checkbox2")).toBeNull(); expect(form.get("Textarea1")).toEqual("textarea1 value"); expect(form.get("Number1")).toEqual("123"); expect(form.get("BaseInput1")).toEqual("base input value"); const input = wrapper.find("input[type=text]") const value = "12345" await input.setValue(value) expect(form.get("Text1")).toEqual(value); const baseInput = wrapper.find(".base-input") baseInput.vm.$emit("change", value) expect(form.get("BaseInput1")).toEqual(value); }) })