 helpers = if typeof require is 'undefined' then window.viewHelpers else require './view_helper'
 
 oldDeferEvery = Batman.DOM.IteratorBinding::deferEvery
-getSelections = (node) -> (c.selected for c in node[0].children when c.nodeType is window.Node.ELEMENT_NODE)
+getSelections = (node) -> node.find('option').map((i, node) -> !!node.selected).toArray()
 getContents = (node) -> node.find('option').map((i, node) -> node.innerHTML).toArray()
 
 QUnit.module 'Batman.View select bindings'


    QUnit.start()

asyncTest 'it binds options created by a foreach and remains consistent when the set instance iterated over swaps', 4, ->
  leo = new Batman.Object ({name: 'leo', id: 1})
  mikey = new Batman.Object ({name: 'mikey', id: 2})

  context = Batman
    heroes: new Batman.Set(leo, mikey).sortedBy('id')
    selected: mikey

  helpers.render  '<select data-bind="selected.id">' +
                    '<option data-foreach-hero="heroes" data-bind-value="hero.id" data-bind="hero.name" />' +
                  '</selected>', context, (node) ->
    deepEqual getContents(node), ['leo', 'mikey']
    equal node[0].value, mikey.get('id')
    context.set 'heroes', new Batman.Set(leo, mikey).sortedBy('id')
    delay ->
      deepEqual getContents(node), ['leo', 'mikey']
      equal node[0].value, mikey.get('id')

asyncTest 'it binds the value of a multi-select box and updates the options when the bound value changes', ->
  context = new Batman.Object

  '''

  helpers.render source, context, (node) ->
    deepEqual context.get('selected.names'), ['crono', 'link']
    deepEqual getSelections(node), []
    deepEqual getContents(node), []
