MCPcopy
hub / github.com/pocketbase/pocketbase / TestHooksExceptionUnwrapping

Function TestHooksExceptionUnwrapping

plugins/jsvm/binds_test.go:1707–1746  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1705}
1706
1707func TestHooksExceptionUnwrapping(t *testing.T) {
1708 app, _ := tests.NewTestApp()
1709 defer app.Cleanup()
1710
1711 goErr := errors.New("test")
1712
1713 vmFactory := func() *goja.Runtime {
1714 vm := goja.New()
1715 BindCore(vm)
1716 vm.Set("$app", app)
1717 vm.Set("goErr", goErr)
1718 return vm
1719 }
1720
1721 pool := newPool(1, vmFactory)
1722
1723 vm := vmFactory()
1724 hooksBinds(app, vm, pool)
1725
1726 _, err := vm.RunString(`
1727 onModelUpdate((e) => {
1728 throw goErr
1729 }, "demo1")
1730 `)
1731 if err != nil {
1732 t.Fatal(err)
1733 }
1734
1735 record, err := app.FindFirstRecordByFilter("demo1", "1=1")
1736 if err != nil {
1737 t.Fatal(err)
1738 }
1739
1740 record.Set("text", "update")
1741
1742 err = app.Save(record)
1743 if !errors.Is(err, goErr) {
1744 t.Fatalf("Expected goError, got %v", err)
1745 }
1746}
1747
1748func TestRouterBindsCount(t *testing.T) {
1749 app, _ := tests.NewTestApp()

Callers

nothing calls this directly

Calls 9

CleanupMethod · 0.95
NewTestAppFunction · 0.92
BindCoreFunction · 0.85
newPoolFunction · 0.85
hooksBindsFunction · 0.85
IsMethod · 0.80
SetMethod · 0.65
SaveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…