You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Otto runtime exposes a Set function for setting a variable, but no equivalent deletion is available. The closest I could come to was another Set to otto.UndefinedValue(), but that doesn't yield the same behavior. The below code snippet describes what I'm trying to achieve.
funcTestOtto(t*testing.T) {
runtime:=otto.New()
_, err:=runtime.Run("console.log(foo)")
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "ReferenceError: 'foo' is not defined")
err=runtime.Set("foo", "bar")
assert.Nil(t, err)
_, err=runtime.Run("console.log(foo)")
assert.Nil(t, err)
err=runtime.Set("foo", otto.UndefinedValue())
assert.Nil(t, err)
_, err=runtime.Run("console.log(foo)")
assert.NotNil(t, err) // fails, err is nilassert.Equal(t, err, "ReferenceError: 'foo' is not defined") // fails, err is nil
}
The text was updated successfully, but these errors were encountered:
The Otto runtime exposes a
Set
function for setting a variable, but no equivalent deletion is available. The closest I could come to was anotherSet
tootto.UndefinedValue()
, but that doesn't yield the same behavior. The below code snippet describes what I'm trying to achieve.The text was updated successfully, but these errors were encountered: