Merge branch 'promise-matching-1314' of https://github.com/sderickson/jasmine
This commit is contained in:
@@ -217,6 +217,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return obj.nodeType > 0;
|
return obj.nodeType > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
j$.isPromise = function(obj) {
|
||||||
|
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
||||||
|
};
|
||||||
|
|
||||||
j$.fnNameFor = function(func) {
|
j$.fnNameFor = function(func) {
|
||||||
if (func.name) {
|
if (func.name) {
|
||||||
return func.name;
|
return func.name;
|
||||||
@@ -2684,6 +2688,12 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var aIsPromise = j$.isPromise(a);
|
||||||
|
var bIsPromise = j$.isPromise(b);
|
||||||
|
if (aIsPromise && bIsPromise) {
|
||||||
|
return a === b;
|
||||||
|
}
|
||||||
|
|
||||||
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
||||||
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
||||||
var length = aStack.length;
|
var length = aStack.length;
|
||||||
|
|||||||
@@ -167,6 +167,16 @@ describe("matchersUtil", function() {
|
|||||||
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("passes for equivalent Promises (GitHub issue #1314)", function() {
|
||||||
|
if (typeof Promise === 'undefined') { return; }
|
||||||
|
|
||||||
|
var p1 = new Promise(function () {}),
|
||||||
|
p2 = new Promise(function () {});
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.matchersUtil.equals(p1, p1)).toBe(true);
|
||||||
|
expect(jasmineUnderTest.matchersUtil.equals(p1, p2)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
describe("when running in a browser", function() {
|
describe("when running in a browser", function() {
|
||||||
function isNotRunningInBrowser() {
|
function isNotRunningInBrowser() {
|
||||||
return typeof document === 'undefined'
|
return typeof document === 'undefined'
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return obj.nodeType > 0;
|
return obj.nodeType > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
j$.isPromise = function(obj) {
|
||||||
|
return typeof jasmineGlobal.Promise !== 'undefined' && obj.constructor === jasmineGlobal.Promise;
|
||||||
|
};
|
||||||
|
|
||||||
j$.fnNameFor = function(func) {
|
j$.fnNameFor = function(func) {
|
||||||
if (func.name) {
|
if (func.name) {
|
||||||
return func.name;
|
return func.name;
|
||||||
|
|||||||
@@ -214,6 +214,12 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var aIsPromise = j$.isPromise(a);
|
||||||
|
var bIsPromise = j$.isPromise(b);
|
||||||
|
if (aIsPromise && bIsPromise) {
|
||||||
|
return a === b;
|
||||||
|
}
|
||||||
|
|
||||||
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
||||||
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
||||||
var length = aStack.length;
|
var length = aStack.length;
|
||||||
|
|||||||
Reference in New Issue
Block a user