Skip to content

Commit 12afcd2

Browse files
committed
Add more tests for Context#call
1 parent ad0ab1b commit 12afcd2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/test_execjs.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ def test_nested_context_call
4848
assert_equal "bar", context.call("a.b.id", "bar")
4949
end
5050

51+
def test_call_with_complex_properties
52+
context = ExecJS.compile("")
53+
assert_equal 2, context.call("function(a, b) { return a + b }", 1, 1)
54+
55+
context = ExecJS.compile("foo = 1")
56+
assert_equal 2, context.call("(function(bar) { return foo + bar })", 1)
57+
end
58+
59+
def test_call_with_this
60+
# Make sure that `this` is indeed the global scope
61+
context = ExecJS.compile(<<-EOF)
62+
name = 123;
63+
64+
function Person(name) {
65+
this.name = name;
66+
}
67+
68+
Person.prototype.getThis = function() {
69+
return this.name;
70+
}
71+
EOF
72+
73+
assert_equal 123, context.call("(new Person('Bob')).getThis")
74+
end
75+
5176
def test_context_call_missing_function
5277
context = ExecJS.compile("")
5378
assert_raises ExecJS::ProgramError do

0 commit comments

Comments
 (0)