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:
parent
ad0ab1bdde
commit
12afcd2696
1 changed files with 25 additions and 0 deletions
|
@ -48,6 +48,31 @@ class TestExecJS < Test
|
|||
assert_equal "bar", context.call("a.b.id", "bar")
|
||||
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
|
||||
context = ExecJS.compile("")
|
||||
assert_raises ExecJS::ProgramError do
|
||||
|
|
Loading…
Reference in a new issue