Skip to content

Commit

Permalink
Throw if Q.noConflict is called in wrong context
Browse files Browse the repository at this point in the history
This makes `Q.noConflict` throw an error if Q is used as a global.
  • Loading branch information
kahnvex committed Apr 27, 2015
1 parent 8cd3005 commit ebc4f77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion q.js
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ Promise.prototype.nodeify = function (nodeback) {
};

Q.noConflict = function() {
console.log('Q.noConflict only works when Q is used as a global');
throw new Error('Q.noConflict only works when Q is used as a global');
};

// All code before this point will be filtered from stack traces.
Expand Down
13 changes: 9 additions & 4 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2503,11 +2503,16 @@ describe("browser support", function () {
});

it("sets the global Q object to its original value", function() {
Q.noConflict();

// In this context the original value of Q is undefined.
if(typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
// If window is not undefined, the tests are running in the browser
// assert that Q.noConflict returns window.Q to it's initial value
// In this context the original value of Q is undefined
Q.noConflict();
expect(Q).toEqual(undefined);
} else {
// If window is undefined the tests are being run in node, and
// Q.noConflict should throw an error
expect(Q.noConflict).toThrow();
}
});
});
Expand Down

0 comments on commit ebc4f77

Please sign in to comment.