Skip to content

Instantly share code, notes, and snippets.

View blukmays's full-sized avatar

Blu Mays blukmays

View GitHub Profile
describe('unicode strings', () => {
it('are \\u prefixed', () => {
const nuclear = '\u2622';
assert.equal(nuclear, '☢');
});
it('value is 4 bytes/digits', () => {
const nuclear = '\u2622';
assert.equal(`no more ${nuclear}`, 'no more ☢');
describe('`Object.is()` determines whether two values are the same', function(){
describe('scalar values', function() {
it('1 is the same as 1', function() {
const areSame = Object.is(1, 1);
assert.equal(areSame, true);
});
it('int 1 is different to string "1"', function() {
const areSame = Object.is(1, '1');
assert.equal(areSame, false);
describe('`Number.isInteger()` determines if a value is an integer', function(){
const isTrue = (what) => assert.equal(what, true);
const isFalse = (what) => assert.equal(what, false);
it('`isInteger` is a static function on `Number`', function() {
const whatType = 'function';
assert.equal(typeof Number.isInteger, whatType);
});
import assert from 'assert'; // is only here for completeness, `assert` is always imported by default
import { equal, deepEqual, notEqual } from 'assert';
import { equal as myEqual } from "assert";
import { default as myAssert } from "assert";
describe('use `import` to import functions that have been exported (somewhere else)', function() {
describe('the import statement', function() {
it('is only allowed on the root level', function() {
// try to comment this out, it will yell at you :)
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);
});
it('it is used when undefined is passed', function() {
let number = (int = 23) => int;
describe('spread with arrays', () => {
it('extracts each array item', function() {
const [a, b] = [...[1, 2]];
assert.equal(a, 1);
assert.equal(b, 2);
});
it('in combination with rest', function() {
const [x, a, b, ...rest] = [...[0, 1, 2, 3, 4, 5]];
describe('rest in function params', () => {
it('must be the last parameter', () => {
const fn = (...rest) => {
assert.deepEqual([1, 2], rest);
};
fn(1, 2);
});
it('can be used to get all other parameters', () => {
describe('`const` is like `let` plus read-only', () => {
describe('scalar values are read-only', () => {
it('number', () => {
const constNum = 0;
//constNum = 1; // Esto daría un: "Uncaught TypeError: Assignment to constant variable"
assert.equal(constNum, 0);
});
describe('arrow functions', function() {
it('are shorter to write', function() {
var func = () => {
return 'I am func';
};
assert.equal(func(), 'I am func');
});
it('a single expression, without curly braces returns too', function() {
describe('Symbol', function() {
it('`Symbol` lives in the global scope', function(){
const expected = Symbol;
assert.equal(Symbol, expected);
});
it('every `Symbol()` is unique', function(){
const sym1 = Symbol();
const sym2 = Symbol();