Merge branch 'add_toBeNullish' of https://github.com/MattMcCherry/jasmine
* Merges #2045 from @MattMcCherry
This commit is contained in:
@@ -150,6 +150,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
|
|||||||
'toBeTrue',
|
'toBeTrue',
|
||||||
'toBeTruthy',
|
'toBeTruthy',
|
||||||
'toBeUndefined',
|
'toBeUndefined',
|
||||||
|
'toBeNullish',
|
||||||
'toContain',
|
'toContain',
|
||||||
'toEqual',
|
'toEqual',
|
||||||
'toHaveSize',
|
'toHaveSize',
|
||||||
@@ -6011,6 +6012,28 @@ getJasmineRequireObj().toBeNull = function() {
|
|||||||
return toBeNull;
|
return toBeNull;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getJasmineRequireObj().toBeNullish = function() {
|
||||||
|
/**
|
||||||
|
* {@link expect} the actual value to be `null` or `undefined`.
|
||||||
|
* @function
|
||||||
|
* @name matchers#toBeNullish
|
||||||
|
* @since 5.6.0
|
||||||
|
* @example
|
||||||
|
* expect(result).toBeNullish():
|
||||||
|
*/
|
||||||
|
function toBeNullish() {
|
||||||
|
return {
|
||||||
|
compare: function(actual) {
|
||||||
|
return {
|
||||||
|
pass: null === actual || void 0 === actual
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return toBeNullish;
|
||||||
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().toBePositiveInfinity = function(j$) {
|
getJasmineRequireObj().toBePositiveInfinity = function(j$) {
|
||||||
/**
|
/**
|
||||||
* {@link expect} the actual value to be `Infinity` (infinity).
|
* {@link expect} the actual value to be `Infinity` (infinity).
|
||||||
|
|||||||
@@ -469,6 +469,24 @@ describe('Matchers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('toBeNullish', function() {
|
||||||
|
verifyPasses(function(env) {
|
||||||
|
env.expect(undefined).toBeNullish();
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyPasses(function(env) {
|
||||||
|
env.expect(null).toBeNullish();
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function(env) {
|
||||||
|
env.expect(1).toBeNullish();
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function(env) {
|
||||||
|
env.expect('').toBeNullish();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('toContain', function() {
|
describe('toContain', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.addCustomEqualityTester(function(a, b) {
|
env.addCustomEqualityTester(function(a, b) {
|
||||||
|
|||||||
57
spec/core/matchers/toBeNullishSpec.js
Normal file
57
spec/core/matchers/toBeNullishSpec.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
describe('toBeNullish', function() {
|
||||||
|
it('passes for null values', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare(null);
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes for undefined values', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare(void 0);
|
||||||
|
expect(result.pass).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails when matching defined values', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare('foo');
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('falsy values', () => {
|
||||||
|
it('fails for 0', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare(0);
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for -0', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare(-0);
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for empty string', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare('');
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for false', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare(false);
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for NaN', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare(NaN);
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails for 0n', function() {
|
||||||
|
const matcher = jasmineUnderTest.matchers.toBeNullish();
|
||||||
|
const result = matcher.compare(BigInt(0));
|
||||||
|
expect(result.pass).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -18,6 +18,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
|
|||||||
'toBeTrue',
|
'toBeTrue',
|
||||||
'toBeTruthy',
|
'toBeTruthy',
|
||||||
'toBeUndefined',
|
'toBeUndefined',
|
||||||
|
'toBeNullish',
|
||||||
'toContain',
|
'toContain',
|
||||||
'toEqual',
|
'toEqual',
|
||||||
'toHaveSize',
|
'toHaveSize',
|
||||||
|
|||||||
21
src/core/matchers/toBeNullish.js
Normal file
21
src/core/matchers/toBeNullish.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
getJasmineRequireObj().toBeNullish = function() {
|
||||||
|
/**
|
||||||
|
* {@link expect} the actual value to be `null` or `undefined`.
|
||||||
|
* @function
|
||||||
|
* @name matchers#toBeNullish
|
||||||
|
* @since 5.6.0
|
||||||
|
* @example
|
||||||
|
* expect(result).toBeNullish():
|
||||||
|
*/
|
||||||
|
function toBeNullish() {
|
||||||
|
return {
|
||||||
|
compare: function(actual) {
|
||||||
|
return {
|
||||||
|
pass: null === actual || void 0 === actual
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return toBeNullish;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user