Skip to content

Instantly share code, notes, and snippets.

View reneviering's full-sized avatar

René Viering reneviering

View GitHub Profile
// 73: Generator - `return` inside a generator is special
// To do: make all tests pass, leave the assert lines unchanged!
describe('`return` in a generator function is special', function() {
describe('the returned value is an IteratorResult (just like any value returned via `yield`)', function() {
it('returns an IteratorResult (an object with the properties `value` and `done`)', function() {
function* generatorFunction() { return 1; }
const returned = generatorFunction().next();
// 72: String - `startsWith()`
// To do: make all tests pass, leave the assert lines unchanged!
describe('`str.startsWith(searchString)` determines whether `str` begins with `searchString`.', function() {
const s = 'the string s';
describe('1st parameter, the string to search for', function() {
it('works with just a character', function() {
const actual = s.startsWith('t');
// 71: String - `repeat()`
// To do: make all tests pass, leave the assert lines unchanged!
describe('`str.repeat(x)` appends `x` copies of `str` to each other and returns it', function() {
describe('pass the count to `str.repeat(count)`', function() {
it('for `1` the string stays the same', function() {
const what = 'one'.repeat(1);
assert.equal(what, 'one');
});
// 70: Set - clear
// To do: make all tests pass, leave the assert lines unchanged!
describe('`clear()` removes all elements from a Set object.', function(){
let set;
beforeEach(() => set = new Set());
it('`set.size` becomes 0', function() {
set.add('one').add(2);
// 69: Reflect - defineProperty
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Reflect.defineProperty()` is like `Object.defineProperty()` but returns a Boolean.', function() {
describe('the function itself', function() {
it('is static on the `Reflect` object', function() {
const name = 'defineProperty';
assert.equal(name in Reflect, true);
});
// 68: Reflect - construct
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Reflect.construct` is the `new` operator as a function', function() {
describe('the function itself', function() {
it('is static on the `Reflect` object', function() {
const name = 'construct';
assert.equal(name in Reflect, true);
});
// 67: object-literal - setter
// To do: make all tests pass, leave the assert lines unchanged!
describe('An object literal can also contain setters', () => {
describe('defining: a setter', function() {
it('by prefixing the property with `set` (and make it a function)', function() {
let theX = null;
const obj = {
set x(newX) { theX = newX; }
// 66: object-literal - getter
// To do: make all tests pass, leave the assert lines unchanged!
describe('An object literal can also contain getters', () => {
it('just prefix the property with `get` (and make it a function)', function() {
const obj = {
get x() { return 'ax'; }
};
// 65: Set - API overview
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Set` API overview', function(){
const api = ['size', 'add', 'clear', 'delete', 'entries', 'forEach', 'has', 'keys', 'values'];
let set;
beforeEach(function() {
set = new Set(api);
});
// 64: Set - delete
// To do: make all tests pass, leave the assert lines unchanged!
describe('`set.delete()` deletes an element from a set', function(){
let set;
beforeEach(() => set = new Set());
describe('use `delete(<value>)` to delete an element', function() {
beforeEach(function() {