Commit 75ae49a2 authored by Stefan Penner's avatar Stefan Penner

Merge pull request #107 from twokul/master

fixing tests for rethrow in IE 6,7,8 as well as phantom/node
parents 885fe7ab 64c22561
var browserGlobal = (typeof window !== 'undefined') ? window : {}; var browserGlobal = (typeof window !== 'undefined') ? window : {};
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var async; var async;
var local = (typeof global !== 'undefined') ? global : this;
// old node // old node
function useNextTick() { function useNextTick() {
...@@ -51,7 +52,7 @@ function useMutationObserver() { ...@@ -51,7 +52,7 @@ function useMutationObserver() {
function useSetTimeout() { function useSetTimeout() {
return function(callback, arg) { return function(callback, arg) {
global.setTimeout(function() { local.setTimeout(function() {
callback(arg); callback(arg);
}, 1); }, 1);
}; };
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
</head> </head>
<body> <body>
<div id="mocha"></div> <div id="mocha"></div>
<script src="../dist/rsvp-2.0.1.js"></script> <script src="../dist/rsvp-2.0.2.js"></script>
<script src="vendor/assert.js"></script> <script src="vendor/assert.js"></script>
<script src="vendor/mocha.js"></script> <script src="vendor/mocha.js"></script>
<script>mocha.setup({ ui: 'bdd', timeout: 200 }); mocha.globals(['setTimeout']);</script> <script>mocha.setup({ ui: 'bdd', timeout: 200 }); mocha.globals(['setTimeout']);</script>
......
/*global describe, specify, it, assert */ /*global describe, specify, it, assert */
var local = (typeof global === "undefined") ? this : global; var local = (typeof global === "undefined") ? this : global,
oldSetTimeout, newSetTimeout;
local.setTimeout = local.setTimeout;
oldSetTimeout = local.setTimeout;
newSetTimeout = function(callback) {
var errorWasThrown;
try {
callback.call(this, arguments);
} catch(e) {
errorWasThrown = true;
}
};
if (typeof Object.getPrototypeOf !== "function") { if (typeof Object.getPrototypeOf !== "function") {
Object.getPrototypeOf = "".__proto__ === String.prototype Object.getPrototypeOf = "".__proto__ === String.prototype
...@@ -727,7 +738,7 @@ describe("RSVP extensions", function() { ...@@ -727,7 +738,7 @@ describe("RSVP extensions", function() {
}); });
describe("RSVP.rethrow", function() { describe("RSVP.rethrow", function() {
var onerror, oldSetTimeout = global.setTimeout; var onerror;
after(function() { after(function() {
global.setTimeout = oldSetTimeout; global.setTimeout = oldSetTimeout;
...@@ -740,19 +751,8 @@ describe("RSVP extensions", function() { ...@@ -740,19 +751,8 @@ describe("RSVP extensions", function() {
it("rethrows an error", function(done) { it("rethrows an error", function(done) {
var thrownError = new Error('I am an error.'); var thrownError = new Error('I am an error.');
local.setTimeout = function (callback) {
done();
var errorWasThrown = false;
try {
callback.call(this, arguments);
} catch(e) {
errorWasThrown = true;
}
assert(errorWasThrown, 'expect that an error was thrown');
};
function expectRejection(reason) { function expectRejection(reason) {
done();
assertEqual(reason, thrownError); assertEqual(reason, thrownError);
} }
...@@ -761,6 +761,8 @@ describe("RSVP extensions", function() { ...@@ -761,6 +761,8 @@ describe("RSVP extensions", function() {
assert(false, value); assert(false, value);
} }
global.setTimeout = newSetTimeout;
RSVP.reject(thrownError). RSVP.reject(thrownError).
fail(RSVP.rethrow). fail(RSVP.rethrow).
then(doNotExpectFulfillment, expectRejection); then(doNotExpectFulfillment, expectRejection);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment