Added a jasmine.exactly asymmetric equality tester
This commit is contained in:
17
src/core/asymmetric_equality/Exactly.js
Normal file
17
src/core/asymmetric_equality/Exactly.js
Normal 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;
|
||||
};
|
||||
@@ -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.
|
||||
|
||||
@@ -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$);
|
||||
|
||||
Reference in New Issue
Block a user