Skip to content

Commit 8b8b884

Browse files
committedJun 30, 2014
Fix Element#inspect for document and window
1 parent d439b88 commit 8b8b884

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎opal/opal-jquery/element.rb

+3
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ def tag_name
259259

260260
def inspect
261261
%x{
262+
if (self[0] === document) return '#<Element [document]>'
263+
else if (self[0] === window ) return '#<Element [window]>'
264+
262265
var val, el, str, result = [];
263266
264267
for (var i = 0, length = self.length; i < length; i++) {

‎spec/element/inspect_spec.rb

+14-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@
77
<p id="lol" class="bar"></div>
88
HTML
99

10-
it "should return a string representation of the elements" do
10+
it "returns a string representation of the elements" do
1111
Element.find('#foo').inspect.should == '#<Element [<div id="foo">]>'
1212
Element.find('.bar').inspect.should == '#<Element [<div class="bar">, <p id="lol" class="bar">]>'
1313
end
1414

15-
it "should return '[]' when called on empty element set" do
15+
it "returns '[]' when called on empty element set" do
1616
Element.find('.inspect-spec-none').inspect.should == '#<Element []>'
1717
end
18+
19+
it "returns '[]' when called on empty element set" do
20+
Element.find('.inspect-spec-none').inspect.should == '#<Element []>'
21+
end
22+
23+
it "returns '[document]' when called on $(document)" do
24+
Element.find(`document`).inspect.should == '#<Element [document]>'
25+
end
26+
27+
it "returns '[window]' when called on $(window)" do
28+
Element.find(`window`).inspect.should == '#<Element [window]>'
29+
end
1830
end

0 commit comments

Comments
 (0)
Please sign in to comment.