Skip to content

Instantly share code, notes, and snippets.

View ivankisyov's full-sized avatar
🤓
Console Logger, Level 4

Ivanman ivankisyov

🤓
Console Logger, Level 4
View GitHub Profile
@ivankisyov
ivankisyov / typeAssersion.md
Created April 4, 2019 03:58
[TS] type assertions
let message;
message = 'test';

let endsWithM = (<string>message).endsWith('m');
@ivankisyov
ivankisyov / til-angular.md
Last active October 8, 2023 09:03
Learn Angular

Learn Angular

import { FormsModule } from '@angular/forms';
...
// FormsModule  to the imports[]  array in your app.module.ts


@ivankisyov
ivankisyov / fakeServer.js
Created January 30, 2019 08:20
Faking a server using Nock
// npm install those first
const nock = require("nock");
const axios = require("axios");
nock("http://www.example.com")
.post("/items")
.reply(201, "user created");
axios
.post("http://www.example.com/items", {
@ivankisyov
ivankisyov / multipleHttpRequests.js
Created January 30, 2019 08:18
Making multiple http requests and logging debugging info
const axios = require("axios");
const postTo = "https://jsonplaceholder.typicode.com/posts";
const patchTo = "https://jsonplaceholder.typicode.com/posts/2"; // todo: make the patch endpoint dynamic
const itemsToBePosted = [
{ title: "foo", body: "bar", userId: 1 },
{ title: "foo", body: "bar", userId: 2 },
{ title: "foo", body: "bar", userId: 3 },
{ title: "foo", body: "bar", userId: 4 }
@ivankisyov
ivankisyov / side-effects.md
Created December 30, 2018 22:17
Side Effects

Side Effects

According to The Mostly Adequate Guide

  • changing the file system
  • inserting a record into a database
  • making an http call
  • mutations
  • printing to the screen / logging
  • obtaining user input
@ivankisyov
ivankisyov / test-driven-development.md
Created December 30, 2018 21:13
Test-driven development

Test-driven development

Think about the code before writing it!

The TDD Cycle:

  1. Test Fails
  2. Test Passes
  3. Refactor
@ivankisyov
ivankisyov / this-js.md
Last active December 29, 2018 16:40
This in JS

This in JS

How to determine what this refers to:

1. Check where the function is being called! Then:

  • Is there a dot and an object preceding that dot. If yes, this will refer to that object
  • Is call or apply or bind used. If yes, this will refer to the first argument which was passed to those methods
  • Do you see the usage of the new keyword. If so, this will refer to the newly created object
  • Is this inside an arrow function. If yes, this will refer to the this of the parent function. Check the parent/enclosing scope
  • If none from above, this will refer to the global object. If in strict mode, this will be undefined
@ivankisyov
ivankisyov / writing-tests-with-jest-on-nodejs.md
Last active December 8, 2022 02:15
Writing Tests with Jest on Node.js

Writing Tests with Jest on Node.js

Installation

npm i --save-dev jest

Configuration

@ivankisyov
ivankisyov / writing-tests-in-js.md
Last active December 30, 2018 21:13
Writing Tests in JS

Writing Tests in JS

Testing Async Code

In order to properly handle async code, you can use the following approaches:

  • use the done callback
  • return the promise(if any of course)
  • use async/await: make sure the callback that you're passing to the it/test function is "asynced"
    • in order to test async code which should fail, you must use try/catch or switch to the second appoach listed here and use the catch method on the promise that had been rejected;
@ivankisyov
ivankisyov / expressions-in-js.md
Last active December 27, 2018 10:17
Expressions in JS

Expressions in JS

Expressions produce value