@@ -96,6 +96,7 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
|||||||
j$.SpyRegistry = jRequire.SpyRegistry(j$);
|
j$.SpyRegistry = jRequire.SpyRegistry(j$);
|
||||||
j$.SpyStrategy = jRequire.SpyStrategy(j$);
|
j$.SpyStrategy = jRequire.SpyStrategy(j$);
|
||||||
j$.StringMatching = jRequire.StringMatching(j$);
|
j$.StringMatching = jRequire.StringMatching(j$);
|
||||||
|
j$.StringContaining = jRequire.StringContaining(j$);
|
||||||
j$.UserContext = jRequire.UserContext(j$);
|
j$.UserContext = jRequire.UserContext(j$);
|
||||||
j$.Suite = jRequire.Suite(j$);
|
j$.Suite = jRequire.Suite(j$);
|
||||||
j$.Timer = jRequire.Timer();
|
j$.Timer = jRequire.Timer();
|
||||||
@@ -487,6 +488,17 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return new j$.StringMatching(expected);
|
return new j$.StringMatching(expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a matcher, 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
|
||||||
|
* @function
|
||||||
|
* @param {String} expected
|
||||||
|
*/
|
||||||
|
j$.stringContaining = function(expected) {
|
||||||
|
return new j$.StringContaining(expected);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a matcher, 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}),
|
* Get a matcher, 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.
|
* that will succeed if the actual value is an `Array` that contains at least the elements in the sample.
|
||||||
@@ -2926,6 +2938,31 @@ getJasmineRequireObj().SetContaining = function(j$) {
|
|||||||
return SetContaining;
|
return SetContaining;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getJasmineRequireObj().StringContaining = function(j$) {
|
||||||
|
function StringContaining(expected) {
|
||||||
|
if (!j$.isString_(expected)) {
|
||||||
|
throw new Error('Expected is not a String');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.expected = expected;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringContaining.prototype.asymmetricMatch = function(other) {
|
||||||
|
if (!j$.isString_(other)) {
|
||||||
|
// Arrays, etc. don't match no matter what their indexOf returns.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.indexOf(this.expected) !== -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
StringContaining.prototype.jasmineToString = function() {
|
||||||
|
return '<jasmine.stringContaining("' + this.expected + '")>';
|
||||||
|
};
|
||||||
|
|
||||||
|
return StringContaining;
|
||||||
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().StringMatching = function(j$) {
|
getJasmineRequireObj().StringMatching = function(j$) {
|
||||||
function StringMatching(expected) {
|
function StringMatching(expected) {
|
||||||
if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
|
if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
|
||||||
|
|||||||
27
spec/core/asymmetric_equality/StringContainingSpec.js
Normal file
27
spec/core/asymmetric_equality/StringContainingSpec.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
describe('StringContaining', function() {
|
||||||
|
it('searches for a provided substring when the expected is a String', function() {
|
||||||
|
var matcher = new jasmineUnderTest.StringContaining('foo');
|
||||||
|
|
||||||
|
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||||
|
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('raises an Error when the expected is not a String', function() {
|
||||||
|
expect(function() {
|
||||||
|
new jasmineUnderTest.StringContaining(/foo/);
|
||||||
|
}).toThrowError(/not a String/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails when the actual is not a String', function() {
|
||||||
|
var matcher = new jasmineUnderTest.StringContaining('x');
|
||||||
|
expect(matcher.asymmetricMatch(['x'])).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("jasmineToString's itself", function() {
|
||||||
|
var matching = new jasmineUnderTest.StringContaining('foo');
|
||||||
|
|
||||||
|
expect(matching.jasmineToString()).toEqual(
|
||||||
|
'<jasmine.stringContaining("foo")>'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -231,6 +231,16 @@ describe('Asymmetric equality testers (Integration)', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('stringContaining', function() {
|
||||||
|
verifyPasses(function(env) {
|
||||||
|
env.expect('foo').toEqual(jasmineUnderTest.stringContaining('o'));
|
||||||
|
});
|
||||||
|
|
||||||
|
verifyFails(function(env) {
|
||||||
|
env.expect('bar').toEqual(jasmineUnderTest.stringContaining('o'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('truthy', function() {
|
describe('truthy', function() {
|
||||||
verifyPasses(function(env) {
|
verifyPasses(function(env) {
|
||||||
env.expect(true).toEqual(jasmineUnderTest.truthy());
|
env.expect(true).toEqual(jasmineUnderTest.truthy());
|
||||||
|
|||||||
24
src/core/asymmetric_equality/StringContaining.js
Normal file
24
src/core/asymmetric_equality/StringContaining.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
getJasmineRequireObj().StringContaining = function(j$) {
|
||||||
|
function StringContaining(expected) {
|
||||||
|
if (!j$.isString_(expected)) {
|
||||||
|
throw new Error('Expected is not a String');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.expected = expected;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringContaining.prototype.asymmetricMatch = function(other) {
|
||||||
|
if (!j$.isString_(other)) {
|
||||||
|
// Arrays, etc. don't match no matter what their indexOf returns.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.indexOf(this.expected) !== -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
StringContaining.prototype.jasmineToString = function() {
|
||||||
|
return '<jasmine.stringContaining("' + this.expected + '")>';
|
||||||
|
};
|
||||||
|
|
||||||
|
return StringContaining;
|
||||||
|
};
|
||||||
@@ -319,6 +319,17 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
return new j$.StringMatching(expected);
|
return new j$.StringMatching(expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a matcher, 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
|
||||||
|
* @function
|
||||||
|
* @param {String} expected
|
||||||
|
*/
|
||||||
|
j$.stringContaining = function(expected) {
|
||||||
|
return new j$.StringContaining(expected);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a matcher, 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}),
|
* Get a matcher, 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.
|
* that will succeed if the actual value is an `Array` that contains at least the elements in the sample.
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
|||||||
j$.SpyRegistry = jRequire.SpyRegistry(j$);
|
j$.SpyRegistry = jRequire.SpyRegistry(j$);
|
||||||
j$.SpyStrategy = jRequire.SpyStrategy(j$);
|
j$.SpyStrategy = jRequire.SpyStrategy(j$);
|
||||||
j$.StringMatching = jRequire.StringMatching(j$);
|
j$.StringMatching = jRequire.StringMatching(j$);
|
||||||
|
j$.StringContaining = jRequire.StringContaining(j$);
|
||||||
j$.UserContext = jRequire.UserContext(j$);
|
j$.UserContext = jRequire.UserContext(j$);
|
||||||
j$.Suite = jRequire.Suite(j$);
|
j$.Suite = jRequire.Suite(j$);
|
||||||
j$.Timer = jRequire.Timer();
|
j$.Timer = jRequire.Timer();
|
||||||
|
|||||||
Reference in New Issue
Block a user