added #toBeTrue and #toBeFalse matchers

This commit is contained in:
Felix Rilling
2019-04-14 10:17:59 +02:00
parent 8fca3b4c11
commit 369e810791
5 changed files with 76 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
describe("toBeFalse", function() {
it("passes for false", function() {
var matcher = jasmineUnderTest.matchers.toBeFalse(),
result;
result = matcher.compare(false);
expect(result.pass).toBe(true);
});
it("fails for non-false", function() {
var matcher = jasmineUnderTest.matchers.toBeFalse(),
result;
result = matcher.compare('foo');
expect(result.pass).toBe(false);
});
});

View File

@@ -0,0 +1,17 @@
describe("toBeTrue", function() {
it("passes for true", function() {
var matcher = jasmineUnderTest.matchers.toBeTrue(),
result;
result = matcher.compare(true);
expect(result.pass).toBe(true);
});
it("fails for non-true", function() {
var matcher = jasmineUnderTest.matchers.toBeTrue(),
result;
result = matcher.compare('foo');
expect(result.pass).toBe(false);
});
});

View File

@@ -4,6 +4,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
'toBe',
'toBeCloseTo',
'toBeDefined',
'toBeFalse',
'toBeFalsy',
'toBeGreaterThan',
'toBeGreaterThanOrEqual',
@@ -13,6 +14,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
'toBeNegativeInfinity',
'toBeNull',
'toBePositiveInfinity',
'toBeTrue',
'toBeTruthy',
'toBeUndefined',
'toContain',

View File

@@ -0,0 +1,20 @@
getJasmineRequireObj().toBeFalse = function() {
/**
* {@link expect} the actual value to be `false`.
* @function
* @name matchers#toBeFalse
* @example
* expect(result).toBeFalse();
*/
function toBeFalse() {
return {
compare: function(actual) {
return {
pass: actual === false
};
}
};
}
return toBeFalse;
};

View File

@@ -0,0 +1,20 @@
getJasmineRequireObj().toBeTrue = function() {
/**
* {@link expect} the actual value to be `true`.
* @function
* @name matchers#toBeTrue
* @example
* expect(result).toBeTrue();
*/
function toBeTrue() {
return {
compare: function(actual) {
return {
pass: actual === true
};
}
};
}
return toBeTrue;
};