From 496981efd0869353e54c073764149df044ab4424 Mon Sep 17 00:00:00 2001 From: maddalax Date: Thu, 3 Oct 2024 15:35:19 -0500 Subject: [PATCH] fix tests --- framework/h/command_test.go | 9 ++++++--- framework/h/lifecycle.go | 7 +------ framework/h/render_test.go | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/framework/h/command_test.go b/framework/h/command_test.go index 3743381..0da8afb 100644 --- a/framework/h/command_test.go +++ b/framework/h/command_test.go @@ -32,17 +32,20 @@ func renderJs(t *testing.T, command Command) string { value := parsed.FirstChild.FirstChild.NextSibling.LastChild.Attr[0].Val isComplex := strings.HasPrefix(value, "__eval_") if !isComplex { - return value + value = strings.ReplaceAll(value, "var e=event;", "") + return strings.ReplaceAll(value, "var self=this;", "") } else { - id := strings.TrimSuffix(value, "(this);") + id := strings.TrimSuffix(value, "(this, event);") script := findScriptById(parsed, id) assert.NotNil(t, script) funcCall := script.LastChild.Data funcCall = strings.ReplaceAll(funcCall, "\n", "") funcCall = strings.ReplaceAll(funcCall, "\t", "") - start := fmt.Sprintf("function %s(self) {", id) + start := fmt.Sprintf("function %s(self, event) {", id) funcCall = strings.TrimPrefix(funcCall, start) funcCall = strings.TrimSuffix(funcCall, "}") + funcCall = strings.ReplaceAll(funcCall, "let e = event;", "") + funcCall = strings.ReplaceAll(funcCall, "var self=this;", "") return funcCall } } diff --git a/framework/h/lifecycle.go b/framework/h/lifecycle.go index 295b50d..1dd199a 100644 --- a/framework/h/lifecycle.go +++ b/framework/h/lifecycle.go @@ -307,12 +307,7 @@ func SetValue(value string) SimpleJsCommand { func SubmitFormOnEnter() ComplexJsCommand { // language=JavaScript return EvalJs(` - if (event.code === 'Enter') { - console.log('submitting form'); - setTimeout(() => { - self.form.dispatchEvent(new Event('submit', { cancelable: true })); - }, 250) - } + if (event.code === 'Enter') { self.form.dispatchEvent(new Event('submit', { cancelable: true })); } `) } diff --git a/framework/h/render_test.go b/framework/h/render_test.go index 10a6662..b38a8df 100644 --- a/framework/h/render_test.go +++ b/framework/h/render_test.go @@ -46,7 +46,7 @@ func TestRender(t *testing.T) { assert.Equal(t, expected, - result) + strings.ReplaceAll(result, "var self=this;var e=event;", "")) } func TestRenderAttributes_1(t *testing.T) {