Skip to content

Commit

Permalink
Add safer test for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tcannon91 committed Dec 7, 2023
1 parent dceb1ff commit 9738bcf
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3014,17 +3014,6 @@ func TestExceptionStringifyError(t *testing.T) {
},
expectedString: "undefined",
},
{
description: "Object",
exceptionVal: func() Value {
testObject := runtime.NewObject()
testObject.Set("foo", "bar")
testObject.Set("fizz", "buzz")

return testObject
},
expectedString: "{\"foo\":\"bar\",\"fizz\":\"buzz\"}",
},
} {
ex := Exception{
val: tc.exceptionVal(),
Expand All @@ -3041,6 +3030,34 @@ func TestExceptionStringifyError(t *testing.T) {

}

func TestExceptionStringifyErrorObject(t *testing.T) {
runtime := New()

expectedData := map[string]string{
"foo": "bar",
"fizz": "buzz",
}

testObject := runtime.NewObject()

for k := range expectedData {
testObject.Set(k, expectedData[k])
}

ex := Exception{
val: testObject,
}

s := ex.StringifyError(runtime)

for expectedKey := range expectedData {
expectedSubstring := fmt.Sprintf("\"%s\":\"%s\"", expectedKey, expectedData[expectedKey])
if !strings.Contains(s, expectedSubstring) {
t.Fatalf("Stringified exception object did not contain expected substring: %s", expectedSubstring)
}
}
}

// TODO(REALMC-10739) return the actual stack trace
func TestErrorCaptureStackTrace(t *testing.T) {
const SCRIPT = `
Expand Down

0 comments on commit 9738bcf

Please sign in to comment.