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
| 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 ☢'); |
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
| 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); |
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
| 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); | |
| }); |
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
| 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 :) |
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
| 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; |
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
| 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]]; |
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
| 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', () => { |
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
| 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); | |
| }); |
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
| 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() { |
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
| 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(); |
NewerOlder