This file contains 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
// 21: spread - with-strings | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('spread with strings', () => { | |
it('simply spread each char of a string', function() { | |
const [a, b] = [...'ab']; | |
assert.equal(a, 'a'); | |
assert.equal(b, 'b'); | |
}); |
This file contains 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 | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('class creation', () => { | |
it('is as simple as `class XXX {}`', function() { | |
class TestClass { | |
} | |
This file contains 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
// 23: class - accessors | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('class accessors (getter and setter)', () => { | |
it('only a getter is defined like a method prefixed with `get`', () => { | |
class MyAccount { | |
get balance() { return Infinity; } | |
} | |
This file contains 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
// 24: class - static keyword | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('inside a class you can use the `static` keyword', () => { | |
describe('for methods', () => { | |
class IntegrationTest {} | |
class UnitTest {} | |
This file contains 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
// 25: class - extends | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('classes can inherit from another', () => { | |
describe('the default super class is Object', () => { | |
it('class A is an instance of Object', () => { | |
class A{}; | |
This file contains 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
// 26: class - more-extends | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('class can inherit from another', () => { | |
it('extend an `old style` "class", a function, still works', () => { | |
class A{}; | |
class B extends A {} | |
assert.equal(new B() instanceof A, true); |
This file contains 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
// 27: class - super inside a method | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('inside a class use `super` to access parent methods', () => { | |
it('use of `super` without `extends` fails (already when transpiling)', () => { | |
class A {hasSuper() { return false; }} | |
assert.equal(new A().hasSuper(), false); |
This file contains 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
// 28: class - super in constructor | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('class', () => { | |
it('if you `extend` a class, use `super()` to call the parent constructor', () => { | |
class A {constructor() { this.levels = 1; }} | |
class B extends A{ | |
constructor() { | |
super(); |
This file contains 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
// 29: array - `Array.from` static method | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('`Array.from` converts an array-like object or list into an Array', () => { | |
const arrayLike = {0: 'one', 1: 'two', length: 2}; | |
it('call `Array.from` with an array-like object', function() { | |
const arr = Array.from(arrayLike); | |
This file contains 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
// 30: array - `Array.of` static method | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('`Array.of` creates an array with the given arguments as elements', () => { | |
it('dont mix it up with `Array(10)`, where the argument is the array length', () => { | |
const arr = Array.of(10); | |
assert.deepEqual(arr, [10]); | |
}); |