Skip to content

Commit 1ca9ca0

Browse files
committed
test(tui): invoke save cmd once and guard against nil
TestMedia_EditProfileCallsMediaFilePath called the cmd returned by form.save() twice — once for the type assertion and again inside the failure t.Fatalf format string. The closure has side effects (records SetProfileMediaFilePath on the mock), so a failure path would double-record and obscure the real assertion. Capture the result in a local variable, invoke once, and add a nil-cmd guard so a future regression in form.save() that returns nil panics fast at the assertion rather than nil-derefencing on cmd().
1 parent cf1fcd2 commit 1ca9ca0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

internal/tui/root_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ func TestMedia_EditProfileCallsMediaFilePath(t *testing.T) {
117117
form := newProfileFormModal(sim, &p, true)
118118
form.fields[fldMediaFile].SetValue("/tmp/loop.mp4")
119119
cmd := form.save()
120-
flash, ok := cmd().(flashMsg)
120+
if cmd == nil {
121+
t.Fatal("form.save() returned nil cmd")
122+
}
123+
// Invoke once — the closure has side effects (records the
124+
// SetProfileMediaFilePath call on the mock); calling it a second
125+
// time inside the failure t.Fatalf would double-record and obscure
126+
// the real assertion below.
127+
result := cmd()
128+
flash, ok := result.(flashMsg)
121129
if !ok {
122-
t.Fatalf("expected flashMsg, got %T", cmd())
130+
t.Fatalf("expected flashMsg, got %T", result)
123131
}
124132
if flash.kind == flashErr {
125133
t.Fatalf("save reported error: %s", flash.text)

0 commit comments

Comments
 (0)