Documentation

QUnit/same

From jQuery JavaScript Library

Jump to: navigation, search

« Back to QUnit

same( actual, expected, [message] )

A deep recursive comparison assertion, working on primitive types, arrays and objects.
Similar to equals, compares the content given objects. Its also more strict than equals: Comparisons are done using ===. For a discussion of the concepts and reasons behind the implementation, see this article.
Arguments:

actualObject
The actual result
expectedObject
The expected result
message (Optional)String
A message to display with the assertion result

Examples:
Add a test that contains a single assertions that is always true.

test("a test", function() {
  var actual = {a: 1};
  equals(actual, {a: 1}, "must fail, same content, but different object, not handled by equals");
  same(actual, {a: "1"}, "must fail, expected value is a string, actual a number");
  same(actual, {a: 1}, "must pass, same content, but different object);
});

NameType