Permalink
Browse files

Improve worker tests

  • Loading branch information...
1 parent 355fe77 commit 4af88b47689f398f92a3e40345dbdb5c5a6c745c @fhd committed Apr 15, 2012
Showing with 10 additions and 14 deletions.
  1. +10 −14 public/test/js/sorting/worker.js
View
24 public/test/js/sorting/worker.js
@@ -7,23 +7,19 @@ test("sleep", 1, function() {
});
test("update", 2, function() {
- var oldSleep = sleep,
- oldPostMessage = postMessage,
- slept, posted;
- sleep = function(ms) {
- slept = ms;
- };
- postMessage = function(message) {
- posted = message;
- };
-
var array = [1, 2, 3];
+
+ sinon.stub(window, "sleep");
+ sinon.stub(window, "postMessage");
+
update(array);
- equal(slept, 200);
- deepEqual(posted.array, array);
- sleep = oldSleep;
- postMessage = oldPostMessage;
+ ok(sleep.calledWith(200), "Should sleep on each update.");
+ ok(postMessage.calledWith({array: array, finished: false}),
+ "The array should be posted to the main thread.");
+
+ sleep.restore();
+ postMessage.restore();
});
test("makeNumeric", 1, function() {

0 comments on commit 4af88b4

Please sign in to comment.