Browse files

Handle string comparisons correctly with equals_

  • Loading branch information...
1 parent dec9232 commit c85079e9d0a0b596ac4cbfabf5d42eb9691406b8 @ragaskar ragaskar committed Mar 17, 2010
Showing with 32 additions and 1 deletion.
  1. +15 −1 lib/jasmine-0.10.1.js
  2. +3 −0 spec/suites/MatchersSpec.js
  3. +4 −0 src/Env.js
  4. +10 −0 src/base.js
View
16 lib/jasmine-0.10.1.js
@@ -93,6 +93,16 @@ jasmine.isArray_ = function(value) {
};
/**
+ * @ignore
+ * @private
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isString_ = function(value) {
+ return Object.prototype.toString.apply(value) === '[object String]';
+};
+
+/**
* Pretty printer for expecations. Takes any object and turns it into a human-readable string.
*
* @param value {Object} an object to be outputted
@@ -822,6 +832,10 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
return b.matches(a);
}
+ if (jasmine.isString_(a) && jasmine.isString_(b)) {
+ return (a == b);
+ }
+
if (typeof a === "object" && typeof b === "object") {
return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
}
@@ -2275,5 +2289,5 @@ jasmine.version_= {
"major": 0,
"minor": 10,
"build": 1,
- "revision": 1268680515
+ "revision": 1268838574
};
View
3 spec/suites/MatchersSpec.js
@@ -54,6 +54,9 @@ describe("jasmine.Matchers", function() {
expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toEqual(false);
expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toEqual(false);
+
+ expect((match(new String("cat")).toEqual("cat"))).toBe(true);
+ expect((match(new String("cat")).toNotEqual("cat"))).toBe(false);
});
it("toEqual to build an Expectation Result", function() {
View
4 src/Env.js
@@ -209,6 +209,10 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
return b.matches(a);
}
+ if (jasmine.isString_(a) && jasmine.isString_(b)) {
+ return (a == b);
+ }
+
if (typeof a === "object" && typeof b === "object") {
return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
}
View
10 src/base.js
@@ -93,6 +93,16 @@ jasmine.isArray_ = function(value) {
};
/**
+ * @ignore
+ * @private
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isString_ = function(value) {
+ return Object.prototype.toString.apply(value) === '[object String]';
+};
+
+/**
* Pretty printer for expecations. Takes any object and turns it into a human-readable string.
*
* @param value {Object} an object to be outputted

0 comments on commit c85079e

Please sign in to comment.