This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 75: Promise - basics | |
describe('a Promise represents an operation that hasn`t completed yet, but is expected in the future', function() { | |
it('`Promise` is a global function', function() { | |
const expectedType = 'function'; | |
assert.equal(typeof Promise, expectedType); | |
}); | |
describe('the constructor', function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 5: arrow functions - basics | |
describe('arrow functions', function() { | |
it('are shorter to write', function() { | |
var func = () => { | |
return 'I am func'; | |
}; | |
assert.equal(func(), 'I am func'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1: template strings - basics | |
describe('a template string, is wrapped in ` (backticks) instead of \' or "', function() { | |
describe('by default, behaves like a normal string', function() { | |
it('just surrounded by backticks', function() { | |
var str = `like a string`; | |
assert.equal(str, 'like a string'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 9: object-literals - basics | |
describe('The object literal allows for new shorthands', () => { | |
const x = 1; | |
const y = 2; | |
describe('with variables', () => { | |
it('the short version for `{x: x}` is {x}', () => { | |
const short = {y}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 7: block scope - let | |
describe('`let` restricts the scope of the variable to the current block', () => { | |
describe('`let` vs. `var`', () => { | |
it('`var` works as usual', () => { | |
if (true) { | |
var varX = true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 10: destructuring - array | |
describe('destructuring arrays makes shorter code', () => { | |
it('extract value from array, e.g. extract 0 into x like so `let [x] = [0];`', () => { | |
let [firstValue] = [1]; | |
assert.strictEqual(firstValue, 1); | |
}); | |
it('swap two variables, in one operation', () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://davidwalsh.name/es6-generators | |
// 49: Generator - creation | |
describe('generator can be created in multiple ways', function() { | |
it('the most common way is by adding `*` after `function`', function() { | |
function* g() {} | |
assertIsGenerator(g()); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 18: rest - as-parameter | |
describe('rest in function params', () => { | |
it('must be the last parameter', () => { | |
const fn = (...rest) => { | |
assert.deepEqual([1, 2], rest); | |
}; | |
fn(1, 2); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 57: Default parameters - basics | |
describe('default parameters make function parameters more flexible', () => { | |
it('define it using an assignment to the parameter `function(param=1){}`', function() { | |
let number = (int = 0) => int; | |
assert.equal(number(), 0); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 22: class - creation | |
describe('class creation', () => { | |
it('is as simple as `class XXX {}`', function() { | |
class TestClass {}; | |
const instance = new TestClass(); | |
assert.equal(typeof instance, 'object'); | |
}); |
OlderNewer