     date: new Date 2015, 8, 1
   ]
 
-  createSparklinesSelection = (data) ->
+  createSparklinesSelection = (parentElement, data) ->
     nestedData = d3.nest()
       .key (d) -> d.label
       .entries data
 
-    svgElement = d3.select document.body
+    svgElement = d3.select parentElement
       .append 'svg'
       .classed 'sparklines-test-case', true
 

      date: 2
      val: 'blabla'
    ]
    sparklinesSelection = createSparklinesSelection SAMPLE_INVALID_DATA
    (-> sparklinesSelection.call @sparklines)
    .should.throw Error
  return


    describe 'when dates are ordered', ->
      beforeEach ->
        @sparklinesSelection = createSparklinesSelection @DOMElement, SAMPLE_DATA_WITH_DATES
        @sparklinesSelection.call @dateSparklines

      describe 'on selection', ->
