Skip to content
Permalink
Browse files

Better check for load events and improved tests

  • Loading branch information...
nvh committed Jun 23, 2016
1 parent ab0f21b commit f254db654a03eefb8df1758c172cf40dd6737c4f
Showing with 22 additions and 3 deletions.
  1. +1 −2 framer/Layer.coffee
  2. +21 −1 test/tests/LayerTest.coffee
@@ -681,8 +681,7 @@ class exports.Layer extends BaseClass
# As an optimization, we will only use a loader
# if something is explicitly listening to the load event

if @_domEventManager.listeners(Events.ImageLoaded) or @_domEventManager.listeners(Events.ImageLoadError)

if @_domEventManager.listeners(Events.ImageLoaded)?.length > 0 or @_domEventManager.listeners(Events.ImageLoadError).length > 0
loader = new Image()
loader.name = imageUrl
loader.src = imageUrl
@@ -138,7 +138,7 @@ describe "Layer", ->
layer._element.style.webkitTransformStyle.should.equal "flat"


it "should set local image", (done) ->
it "should set local image", ->

prefix = "../"
imagePath = "static/test.png"
@@ -151,12 +151,32 @@ describe "Layer", ->
image = layer.props.image
layer.props.image.should.equal fullPath

layer.style["background-image"].indexOf(imagePath).should.not.equal(-1)
layer.style["background-image"].indexOf("file://").should.not.equal(-1)
layer.style["background-image"].indexOf("?nocache=").should.not.equal(-1)

it "should set local image when listening to load events", (done) ->
prefix = "../"
imagePath = "static/test.png"
fullPath = prefix + imagePath
layer = new Layer

layer.on Events.ImageLoaded, ->
layer.style["background-image"].indexOf(imagePath).should.not.equal(-1)
layer.style["background-image"].indexOf("file://").should.not.equal(-1)
layer.style["background-image"].indexOf("?nocache=").should.not.equal(-1)
done()

layer.image = fullPath
layer.image.should.equal fullPath

image = layer.props.image
layer.props.image.should.equal fullPath

layer.style["background-image"].indexOf(imagePath).should.equal(-1)
layer.style["background-image"].indexOf("file://").should.equal(-1)
layer.style["background-image"].indexOf("?nocache=").should.equal(-1)

#layer.computedStyle()["background-size"].should.equal "cover"
#layer.computedStyle()["background-repeat"].should.equal "no-repeat"

1 comment on commit f254db6

@koenbok

This comment has been minimized.

Copy link
Owner

koenbok commented on f254db6 Jun 25, 2016

👌

Please sign in to comment.
You can’t perform that action at this time.