Added a jasmine.exactly asymmetric equality tester

This commit is contained in:
Steve Gravrock
2022-05-14 17:01:38 -07:00
parent c24b2f5a73
commit 0c87d47318
6 changed files with 93 additions and 13 deletions

View File

@@ -0,0 +1,17 @@
getJasmineRequireObj().Exactly = function(j$) {
class Exactly {
constructor(expected) {
this.expected_ = expected;
}
asymmetricMatch(actual) {
return actual === this.expected_;
}
jasmineToString(pp) {
return `<jasmine.exactly(${pp(this.expected_)})>`;
}
}
return Exactly;
};

View File

@@ -283,6 +283,18 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
return new j$.Empty();
};
/**
* 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.exactly
* @function
* @param {Object} sample - The value to compare the actual to.
*/
j$.exactly = function(sample) {
return new j$.Exactly(sample);
};
/**
* 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.

View File

@@ -91,6 +91,7 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
j$.Falsy = jRequire.Falsy(j$);
j$.Empty = jRequire.Empty(j$);
j$.NotEmpty = jRequire.NotEmpty(j$);
j$.Exactly = jRequire.Exactly(j$);
j$.matchers = jRequire.requireMatchers(jRequire, j$);
j$.asyncMatchers = jRequire.requireAsyncMatchers(jRequire, j$);