Skip to content

Commit

Permalink
Added matcher for jQuery.fn.escape() to match '"' and '"'
Browse files Browse the repository at this point in the history
In the browser innerHTML returns " and JSDOM returns " so for now we
use a regular expression to match both.
  • Loading branch information
aron committed Jun 29, 2011
1 parent 5d5137a commit cf62d3e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions test/spec/extensions_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ describe 'jQuery.escape()', ->
describe 'jQuery.fn.escape()', ->
it "should set the innerHTML of the elements but escape any HTML into entities", ->
div = $('<div />').escape('<>"&')
expect(div.html()).toEqual('&lt;&gt;&quot;&amp;')
# Match either &quot; or " as JSDOM keeps quotes escaped but the browser does not.
expect(div.html()).toMatch(/&lt;&gt;(&quot;|")&amp;/)

div = $('<div />').escape('<script>alert("hello")</script>')
expect(div.html()).toEqual('&lt;script&gt;alert(&quot;hello&quot;)&lt;/script&gt;')
expect(div.html()).toMatch(/&lt;script&gt;alert\((&quot;|")hello(&quot;|")\)&lt;\/script&gt;/)

it "should return the original jQuery collection", ->
div = $('<div />').escape('<>"&')
Expand Down

0 comments on commit cf62d3e

Please sign in to comment.