Add more chaining tests join, replace, & split.

This commit is contained in:
jdalton
2015-03-07 00:23:56 -08:00
parent bf96c30187
commit 0f201e3fd8

View File

@@ -15571,19 +15571,27 @@
QUnit.module('lodash(...).join'); QUnit.module('lodash(...).join');
(function() { (function() {
var array = [1, 2, 3];
test('should return join all array elements into a string', 2, function() { test('should return join all array elements into a string', 2, function() {
if (!isNpm) { if (!isNpm) {
var array = [1, 2, 3], var wrapped = _(array);
wrapped = _(array), strictEqual(wrapped.join('.'), '1.2.3');
actual = wrapped.join('.');
strictEqual(actual, '1.2.3');
strictEqual(wrapped.value(), array); strictEqual(wrapped.value(), array);
} }
else { else {
skipTest(2); skipTest(2);
} }
}); });
test('should return a wrapped value when explicitly chaining', 1, function() {
if (!isNpm) {
ok(_(array).chain().join('.') instanceof _);
}
else {
skipTest();
}
});
}()); }());
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
@@ -15656,18 +15664,25 @@
QUnit.module('lodash(...).replace'); QUnit.module('lodash(...).replace');
(function() { (function() {
test('should support string replace', 2, function() { test('should replace the matched pattern', 2, function() {
if (!isNpm) { if (!isNpm) {
var string = 'hi hidash', var wrapped = _('abcdef');
wrapped = _(string); strictEqual(wrapped.replace('def', '123'), 'abc123');
strictEqual(wrapped.replace(/[bdf]/g, '-'), 'a-c-e-');
deepEqual(wrapped.replace('hi', 'lo').value(), 'lo hidash');
deepEqual(wrapped.replace(/hi/g, 'lo').value(), 'lo lodash');
} }
else { else {
skipTest(2); skipTest(2);
} }
}); });
test('should return a wrapped value when explicitly chaining', 1, function() {
if (!isNpm) {
ok(_('abc').chain().replace('b', '_') instanceof _);
}
else {
skipTest();
}
});
}()); }());
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
@@ -15844,31 +15859,24 @@
QUnit.module('lodash(...).split'); QUnit.module('lodash(...).split');
(function() { (function() {
test('should support string split', 1, function() { test('should support string split', 2, function() {
if (!isNpm) { if (!isNpm) {
var string = 'hi ya', var wrapped = _('abcde');
wrapped = _(string), deepEqual(wrapped.split('c').value(), ['ab', 'de']);
actual = ['hi', 'ya']; deepEqual(wrapped.split(/[bd]/).value(), ['a', 'c', 'e']);
deepEqual(wrapped.split(' ').value(), actual);
} }
else { else {
skipTest(1); skipTest(2);
} }
}); });
}());
(function() {
test('should allow mixed string and array prototype methods', 1, function() { test('should allow mixed string and array prototype methods', 1, function() {
if (!isNpm) { if (!isNpm) {
var string = 'hi ya', var wrapped = _('abc');
wrapped = _(string), strictEqual(wrapped.split('b').join(','), 'a,c');
actual = 'hi,ya';
deepEqual(wrapped.split(' ').join(','), actual);
} }
else { else {
skipTest(1); skipTest();
} }
}); });
}()); }());