mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
test(verifier): cross-extractor read guard and named()
This commit is contained in:
1 parent
973ada4983
commit
725b2fe1a8
1 file changed
+34
@@ -0,0 +1,34 @@
|
||||
package verifier
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPushSnapshot_CrossExtractorReadIsGuarded(t *testing.T) {
|
||||
verifier := newVerifier(t)
|
||||
mustLoad(t, verifier, `
|
||||
const a = __sanderling__.extract(state => 1);
|
||||
const b = __sanderling__.extract(() => a.current);
|
||||
globalThis.a = a;
|
||||
globalThis.b = b;
|
||||
`)
|
||||
err := verifier.PushSnapshot(SnapshotInput{Snapshots: Snapshots{}})
|
||||
if err == nil {
|
||||
t.Fatal("expected guard error, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "inside another extractor is not allowed") {
|
||||
t.Errorf("guard error wrong: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtract_NamedSetsExtractorName(t *testing.T) {
|
||||
verifier := newVerifier(t)
|
||||
mustLoad(t, verifier, `
|
||||
const route = __sanderling__.extract(state => "home").named("route");
|
||||
globalThis.route = route;
|
||||
`)
|
||||
if got := verifier.extractors[0].name; got != "route" {
|
||||
t.Errorf("named() did not set name: got %q, want %q", got, "route")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user