Skip to content

Commit

Permalink
Added unit tests for src/content/api.jl
Browse files Browse the repository at this point in the history
Includes a @test_throws which verifies the bug in JuliaGizmos#109. This passes
before the fix:
Test Summary:  | Pass  Total
content! Tests |    7      7
  • Loading branch information
NHDaly committed Jan 17, 2018
1 parent e25741d commit d9c00f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/api.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Blink
using Base.Test

@testset "content! Tests" begin
w = Window(Blink.@d(:show => false)); sleep(5.0)
body!(w, ""); sleep(1.0) # body! is not synchronous.
@test (@js w document.querySelector("body").innerHTML) == ""

# Test reloading body and a selector element.
html = """<div id="a">hi world</div><div id="b">bye</div>"""
body!(w, html); sleep(1.0)
@test (@js w document.getElementById("a").innerHTML) == "hi world"
@test (@js w document.getElementById("b").innerHTML) == "bye"
content!(w, "div", "hello world"); sleep(1.0)
@test (@js w document.getElementById("a").innerHTML) == "hello world"
# TODO(nhdaly): Is this right? Should content!(w,"div",...) change _all_ divs?
@test (@js w document.getElementById("b").innerHTML) == "bye"

# Test `fade` parameter and scripts:
fadeTestHtml = """<script>var testJS = "test";</script><div id="d">hi world</div>"""
@testset "Fade True" begin
# Must create a new window to ensure javascript is reset.
w = Window(Blink.@d(:show => false)); sleep(5.0)

body!(w, fadeTestHtml; fade=true); sleep(1.0)
@test (@js w testJS) == "test"
end
@testset "Fade False" begin
# Must create a new window to ensure javascript is reset.
w = Window(Blink.@d(:show => false)); sleep(5.0)

body!(w, fadeTestHtml; fade=false); sleep(1.0)
@test_throws Blink.JSError (@js w testJS) == "test" # THIS IS AN ERROR, should not throw.
end
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ w = Window(Blink.@d(:show => false)); sleep(5.0)

@test sprint(Blink.jsexpr, :(Dict("a" => 1, :b => 10))) == "{\"a\":1,b:10}"

include("api.jl");

cleanup && AtomShell.remove()

0 comments on commit d9c00f1

Please sign in to comment.