1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Add more tests for Context#call

This commit is contained in:
Magnus Holm 2018-06-02 21:52:18 +02:00
parent ad0ab1bdde
commit 12afcd2696

View file

@ -48,6 +48,31 @@ class TestExecJS < Test
assert_equal "bar", context.call("a.b.id", "bar") assert_equal "bar", context.call("a.b.id", "bar")
end end
def test_call_with_complex_properties
context = ExecJS.compile("")
assert_equal 2, context.call("function(a, b) { return a + b }", 1, 1)
context = ExecJS.compile("foo = 1")
assert_equal 2, context.call("(function(bar) { return foo + bar })", 1)
end
def test_call_with_this
# Make sure that `this` is indeed the global scope
context = ExecJS.compile(<<-EOF)
name = 123;
function Person(name) {
this.name = name;
}
Person.prototype.getThis = function() {
return this.name;
}
EOF
assert_equal 123, context.call("(new Person('Bob')).getThis")
end
def test_context_call_missing_function def test_context_call_missing_function
context = ExecJS.compile("") context = ExecJS.compile("")
assert_raises ExecJS::ProgramError do assert_raises ExecJS::ProgramError do