mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-09-09 08:00:47 +02:00
backported JSVM toString
This commit is contained in:
@@ -47,7 +47,7 @@ func TestBaseBindsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
|
||||
testBindsCount(vm, "this", 17, t)
|
||||
testBindsCount(vm, "this", 18, t)
|
||||
}
|
||||
|
||||
func TestBaseBindsSleep(t *testing.T) {
|
||||
@@ -92,6 +92,41 @@ func TestBaseBindsReaderToString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsToString(t *testing.T) {
|
||||
vm := goja.New()
|
||||
baseBinds(vm)
|
||||
vm.Set("scenarios", []struct {
|
||||
Name string
|
||||
Value any
|
||||
Expected string
|
||||
}{
|
||||
{"null", nil, ""},
|
||||
{"string", "test", "test"},
|
||||
{"number", -12.4, "-12.4"},
|
||||
{"bool", true, "true"},
|
||||
{"arr", []int{1, 2, 3}, `[1,2,3]`},
|
||||
{"obj", map[string]any{"test": 123}, `{"test":123}`},
|
||||
{"reader", strings.NewReader("test"), "test"},
|
||||
{"struct", struct {
|
||||
Name string
|
||||
private string
|
||||
}{Name: "123", private: "456"}, `{"Name":"123"}`},
|
||||
})
|
||||
|
||||
_, err := vm.RunString(`
|
||||
for (let s of scenarios) {
|
||||
let result = toString(s.value)
|
||||
|
||||
if (result != s.expected) {
|
||||
throw new Error('[' + s.name + '] Expected string ' + s.expected + ', got ' + result);
|
||||
}
|
||||
}
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseBindsCookie(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
Reference in New Issue
Block a user