Skip to content

Instantly share code, notes, and snippets.

View underwindfall's full-sized avatar
🐌
Making Progress

Qifan Yang underwindfall

🐌
Making Progress
View GitHub Profile
// 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');
});
// 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 {
}
// 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; }
}
// 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 {}
// 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{};
// 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);
// 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);
// 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();
// 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);
// 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]);
});