Skip to content
This repository has been archived by the owner on Apr 26, 2018. It is now read-only.

Commit

Permalink
Combine 'attach' event specs for calling $.fn.append with both mult…
Browse files Browse the repository at this point in the history
…iple args and a single arg
  • Loading branch information
nathansobo committed Apr 26, 2012
1 parent f0ac76f commit 00e093a
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions space-pen-spec.coffee
Expand Up @@ -2,6 +2,8 @@ describe "View", ->
view = null

describe "View objects", ->
TestView = null

beforeEach ->
class Subview extends View
@content: (params, otherArg) ->
Expand Down Expand Up @@ -125,17 +127,22 @@ describe "View", ->

expect(-> new BadView).toThrow("View markup must have a single root element")

describe "when a view is inserted within another element with jquery", ->
[content, attachHandler, subviewAttachHandler] = []
describe "when a view is attached to another element via jQuery", ->
[content, view2, view3, attachHandler, subviewAttachHandler, view2AttachHandler, view3AttachHandler] = []

beforeEach ->
view2 = new TestView
view3 = new TestView

attachHandler = jasmine.createSpy 'attachHandler'
subviewAttachHandler = jasmine.createSpy 'subviewAttachHandler'
view2AttachHandler = jasmine.createSpy 'view2AttachHandler'
view3AttachHandler = jasmine.createSpy 'view3AttachHandler'

view.on 'attach', attachHandler
view.subview.on 'attach', subviewAttachHandler

it "accepts undefined arguments as jQuery does", ->
view.append undefined
view2.on 'attach', view2AttachHandler
view3.on 'attach', view3AttachHandler

describe "when attached to an element that is on the DOM", ->
beforeEach ->
Expand All @@ -144,10 +151,12 @@ describe "View", ->
afterEach ->
content.empty()

it "triggers an 'attach' event on the view and its subviews", ->
content.append view
it "triggers an 'attach' event on all appended views and their subviews", ->
content.append view, [view2, view3]
expect(attachHandler).toHaveBeenCalled()
expect(subviewAttachHandler).toHaveBeenCalled()
expect(view2AttachHandler).toHaveBeenCalled()
expect(view3AttachHandler).toHaveBeenCalled()

view.detach()
content.empty()
Expand All @@ -160,33 +169,15 @@ describe "View", ->
expect(attachHandler).toHaveBeenCalled()
expect(subviewAttachHandler).toHaveBeenCalled()

describe "with multiple arguments", ->
[view2, view3, view2Handler, view3Handler] = []

beforeEach ->
view2Class = class extends View
@content: -> @div id: "view2"
view3Class = class extends View
@content: -> @div id: "view3"
view2 = new view2Class
view3 = new view3Class
view2Handler = jasmine.createSpy 'view2Handler'
view3Handler = jasmine.createSpy 'view3Handler'
view2.on 'attach', view2Handler
view3.on 'attach', view3Handler

it "triggers an 'attach' event on all args", ->
content.append view, [view2, view3]
expect(attachHandler).toHaveBeenCalled()
expect(view2Handler).toHaveBeenCalled()
expect(view3Handler).toHaveBeenCalled()

describe "when attached to an element that is not on the DOM", ->
it "does not trigger an attach event", ->
fragment = $('<div>')
fragment.append view
expect(attachHandler).not.toHaveBeenCalled()

it "allows $.fn.append to be called with undefined without raising an exception", ->
view.append undefined

describe "View.render (bound to $$)", ->
it "renders a document fragment based on tag methods called by the given function", ->
fragment = $$ ->
Expand Down

0 comments on commit 00e093a

Please sign in to comment.