mocha.setup('bdd');
var expect = chai.expect;
describe('Spread operator tests', function() {
it('Can be used to call a function', function() {
const arr = [1, 2];
const fn = (no1, no2) => {
expect(arr[0]).to.equal(no1);
expect(arr[1]).to.equal(no2);
};
fn(...arr);
});
it('Can be used to find the max in an array',function(){
const arr = [1, 2,3,4,5,6];
expect(Math.max(...arr)).to.equal(6);
});
it ('Can be used to concat arrays',function(){
const arr1= [1, 2,3,4,5,6];
const arr2= [7,8,9,10];
const arr3 = [...arr1,...arr2];
expect(arr3.length).to.equal(10);
});
it ('Can be used to place an array at any point in another array',function(){
const arr1 = [5,6,7];
const arr2 = [1,2,3,...arr1,8,9];
expect(arr2.length).to.equal(8);
});
it('Can be used to copy arrays',function(){
const arr1 = [1,2,3];
const arr2 = [...arr1];
expect(arr2.length).to.equal(3);
});
it('Can be used with dates',function(){
const arr = [2015,1,1];
const d = new Date(...arr);
expect(new Date(2015,1,1).toString()).to.deep.equal(d.toString());
})
});
mocha.run();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.