Skip to content

Commit

Permalink
Docs: Improved discoverability of asymmetric equality testers
Browse files Browse the repository at this point in the history
  • Loading branch information
sgravrock committed Jul 3, 2024
1 parent cc69edf commit 3d54184
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 86 deletions.
129 changes: 86 additions & 43 deletions lib/jasmine-core/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is an instance of the specified class/constructor.
* @name jasmine.any
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value being compared is an instance of the specified class/constructor.
* @name asymmetricEqualityTesters.any
* @emittedName jasmine.any
* @since 1.3.0
* @function
* @param {Constructor} clazz - The constructor to check against.
Expand All @@ -412,9 +413,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is not `null` and not `undefined`.
* @name jasmine.anything
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value being compared is not `null` and not `undefined`.
* @name asymmetricEqualityTesters.anything
* @emittedName jasmine.anything
* @since 2.2.0
* @function
*/
Expand All @@ -423,9 +425,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is `true` or anything truthy.
* @name jasmine.truthy
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value being compared is `true` or anything truthy.
* @name asymmetricEqualityTesters.truthy
* @emittedName jasmine.truthy
* @since 3.1.0
* @function
*/
Expand All @@ -434,9 +437,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is `null`, `undefined`, `0`, `false` or anything falsey.
* @name jasmine.falsy
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value being compared is `null`, `undefined`, `0`, `false` or anything
* falsy.
* @name asymmetricEqualityTesters.falsy
* @emittedName jasmine.falsy
* @since 3.1.0
* @function
*/
Expand All @@ -445,9 +450,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is empty.
* @name jasmine.empty
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value being compared is empty.
* @name asymmetricEqualityTesters.empty
* @emittedName jasmine.empty
* @since 3.1.0
* @function
*/
Expand All @@ -456,10 +462,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher}
* that passes if the actual value is the same as the sample as determined
* by the `===` operator.
* @name jasmine.is
* Get an {@link AsymmetricEqualityTester} that passes if the actual value is
* the same as the sample as determined by the `===` operator.
* @name asymmetricEqualityTesters.is
* @emittedName jasmine.is
* @function
* @param {Object} sample - The value to compare the actual to.
*/
Expand All @@ -468,9 +474,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is not empty.
* @name jasmine.notEmpty
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value being compared is not empty.
* @name asymmetricEqualityTesters.notEmpty
* @emittedName jasmine.notEmpty
* @since 3.1.0
* @function
*/
Expand All @@ -479,9 +486,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared contains at least the keys and values.
* @name jasmine.objectContaining
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value being compared contains at least the specified keys and values.
* @name asymmetricEqualityTesters.objectContaining
* @emittedName jasmine.objectContaining
* @since 1.3.0
* @function
* @param {Object} sample - The subset of properties that _must_ be in the actual.
Expand All @@ -491,9 +499,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value is a `String` that matches the `RegExp` or `String`.
* @name jasmine.stringMatching
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value is a `String` that matches the `RegExp` or `String`.
* @name asymmetricEqualityTesters.stringMatching
* @emittedName jasmine.stringMatching
* @since 2.2.0
* @function
* @param {RegExp|String} expected
Expand All @@ -503,9 +512,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value is a `String` that contains the specified `String`.
* @name jasmine.stringContaining
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value is a `String` that contains the specified `String`.
* @name asymmetricEqualityTesters.stringContaining
* @emittedName jasmine.stringContaining
* @since 3.10.0
* @function
* @param {String} expected
Expand All @@ -515,9 +525,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value is an `Array` that contains at least the elements in the sample.
* @name jasmine.arrayContaining
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value is an `Array` that contains at least the elements in the sample.
* @name asymmetricEqualityTesters.arrayContaining
* @emittedName jasmine.arrayContaining
* @since 2.2.0
* @function
* @param {Array} sample
Expand All @@ -527,9 +538,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value is an `Array` that contains all of the elements in the sample in any order.
* @name jasmine.arrayWithExactContents
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
* value is an `Array` that contains all of the elements in the sample in
* any order.
* @name asymmetricEqualityTesters.arrayWithExactContents
* @emittedName jasmine.arrayWithExactContents
* @since 2.8.0
* @function
* @param {Array} sample
Expand All @@ -539,10 +552,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if every key/value pair in the sample passes the deep equality comparison
* Get an {@link AsymmetricEqualityTester} that will succeed if every
* key/value pair in the sample passes the deep equality comparison
* with at least one key/value pair in the actual value being compared
* @name jasmine.mapContaining
* @name asymmetricEqualityTesters.mapContaining
* @emittedName jasmine.mapContaining
* @since 3.5.0
* @function
* @param {Map} sample - The subset of items that _must_ be in the actual.
Expand All @@ -552,10 +566,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};

/**
* Get an {@link AsymmetricEqualityTester}, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if every item in the sample passes the deep equality comparison
* Get an {@link AsymmetricEqualityTester} that will succeed if every item
* in the sample passes the deep equality comparison
* with at least one item in the actual value being compared
* @name jasmine.setContaining
* @name asymmetricEqualityTesters.setContaining
* @emittedName jasmine.setContaining
* @since 3.5.0
* @function
* @param {Set} sample - The subset of items that _must_ be in the actual.
Expand Down Expand Up @@ -8436,6 +8451,12 @@ getJasmineRequireObj().interface = function(jasmine, env) {
}),

/**
* <p>Members of the jasmine global.</p>
* <p>Note: The members of the
* {@link asymmetricEqualityTesters|asymmetricEqualityTesters namespace}
* are also accessed via the jasmine global, but due to jsdoc limitations
* they are not listed here.</p>
*
* @namespace jasmine
*/
jasmine: jasmine
Expand Down Expand Up @@ -8569,6 +8590,28 @@ getJasmineRequireObj().interface = function(jasmine, env) {
return env.setDefaultSpyStrategy(defaultStrategyFn);
};

/**
* {@link AsymmetricEqualityTester|Asymmetric equality testers} allow for
* non-exact matching in matchers that use Jasmine's deep value equality
* semantics, such as {@link matchers#toEqual|toEqual},
* {@link matchers#toContain|toContain}, and
* {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}.
*
* @example
* const someComplexObject = {
* foo: 'bar',
* baz: 'a string that contains "something"',
* qux: 'whatever'
* };
* // Passes.
* expect(someComplexObject).toEqual(jasmine.objectContaining({
* foo: 'bar',
* baz: jasmine.stringContaining('something')
* });
*
* @namespace asymmetricEqualityTesters
*/

return jasmineInterface;
};

Expand Down
Loading

0 comments on commit 3d54184

Please sign in to comment.