             return [p, (-> resolve = true), (-> reject = true)]
         , 'The result of while()'
 
+    it 'should call the loop test with the provided context', ->
+        context = {}
+        testFn = trackCalls ->
+            expect(this).toBe context
+            return true
+        bodyFn = ->
+
+        p = backburner.while testFn, bodyFn, context
+        waitsFor (-> testFn.called), 'testFn was never called', WAIT_TIME
+
     it 'should call the loop body if the loop test returns true', ->
         testFn = ->
             return true
         bodyFn = callTrackingFn()
         p = backburner.while testFn, bodyFn
-        p.fail (e) ->
+        waitsFor (-> bodyFn.called), 'bodyFn was never called', WAIT_TIME
+        runs ->
             expect(bodyFn.called).toBe true
-        waits WAIT_TIME
+
+    it 'should not call the loop body if the loop test returns false', ->
+        called = false
+        testFn = ->
+            called = true
+            return false
+        bodyFn = callTrackingFn()
+        p = backburner.while testFn, bodyFn
+        p.done (e) ->
+            expect(bodyFn.called).not.toBe true
+        waitsFor (-> called), 'testFn was never called', WAIT_TIME
+
+    it 'should call the loop body with the provided context', ->
+        context = {}
+        testFn = ->
+            return true
+        bodyFn = trackCalls ->
+            expect(this).toBe context
+            @thisTask.resolve()
+
+        p = backburner.while testFn, bodyFn, context
+        waitsFor (-> bodyFn.called), 'bodyFn was never called', WAIT_TIME
 
     it 'should resolve if the loop test returns false', ->
-        testFn = ->
+        testFn = trackCalls ->
             return false
         bodyFn = ->
-        resolved = false
         p = backburner.while testFn, bodyFn
-        p.done (e) ->
-            resolved = true
-        waits WAIT_TIME
+        waitsFor (-> testFn.called), 'testFn was never called', WAIT_TIME
         runs ->
-            expect(resolved).toBe true
+            expect(p.isResolved()).toBe true
 
-    it 'should reject and pass the error if the loop test throws', ->
-        testFn = ->
-            throw 42
-        bodyFn = ->
-        p = backburner.while testFn, bodyFn
-        p.fail (e) ->
-            expect(e).toBe 42
-        waits WAIT_TIME
-
-    it 'should reject and pass the error if the loop body throws', ->
+    it 'should not resolve if the loop test returns true', ->
         testFn = ->
             return true
         bodyFn = ->
+        p = backburner.while testFn, bodyFn
+        waits WAIT_TIME
+        runs ->
+            expect(p.isResolved()).not.toBe true
+
+    it 'should rejectWith the passed context and pass the error if the loop test throws', ->
+        context = {}
+        testFn = trackCalls ->
             throw 42
-        p = backburner.while testFn, bodyFn
+        bodyFn = ->
+        p = backburner.while testFn, bodyFn, context
         p.fail (e) ->
             expect(e).toBe 42
-        waits WAIT_TIME
+            expect(this).toBe context
+        waitsFor (-> testFn.called), 'testFn was never called', WAIT_TIME
+        runs ->
+            expect(p.isRejected()).toBe true
+
+    it 'should rejectWith the passed context and pass the error if the loop body throws', ->
+        context = {}
+        testFn = trackCalls ->
+            return true
+        bodyFn = ->
+            throw 42
+        p = backburner.while testFn, bodyFn, context
+        p.fail (e) ->
+            expect(e).toBe 42
+            expect(this).toBe context
+        waitsFor (-> testFn.called), 'testFn was never called', WAIT_TIME
+        runs ->
+            expect(p.isRejected()).toBe true
+
+    it 'should behave as expected in a simple loop', ->
+        context =
+            i: 0
+        testFn = ->
+            @i < 23
+        bodyFn = ->
+            @i += 1
+        p = backburner.while testFn, bodyFn, context
+        p.done (e) ->
+            expect(@i).toBe 23
+        waitsFor p.isResolved
+

{describeTaskPromise} = require('task')
WAIT_TIME = 50

backburner = require('backburner')


    return ->
        arguments.callee.called = true

trackCalls = (fn) ->
    fn ?= ->
    return ->
        arguments.callee.called = true
        return fn.apply this, arguments

describe 'backburner.while', ->
    backburner.killAll()
    afterEach = ->
        backburner.killAll()

    describeTaskPromise ->
