-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathjsonstring_test.go
More file actions
28 lines (25 loc) · 660 Bytes
/
Copy pathjsonstring_test.go
File metadata and controls
28 lines (25 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package templ_test
import (
"testing"
"github.com/a-h/templ"
)
func TestJSONString(t *testing.T) {
t.Run("renders input data as a JSON string", func(t *testing.T) {
data := map[string]any{"foo": "bar"}
actual, err := templ.JSONString(data)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
expected := "{\"foo\":\"bar\"}"
if actual != expected {
t.Fatalf("unexpected output: want %q, got %q", expected, actual)
}
})
t.Run("returns an error if the data cannot be marshalled", func(t *testing.T) {
data := make(chan int)
_, err := templ.JSONString(data)
if err == nil {
t.Fatalf("expected an error, got nil")
}
})
}