Skip to content

Instantly share code, notes, and snippets.

View Mikhail-MM's full-sized avatar

Mikhail Maslyuk Mikhail-MM

View GitHub Profile
https://jobs.libertymutualgroup.com/job/15004144/senior-software-engineer-remote/
https://jobs.libertymutualgroup.com/job/14669200/senior-software-engineer-remote-remote/
@Mikhail-MM
Mikhail-MM / pipe.js
Created January 13, 2022 16:24
pipe-gist
export const pipe = (...fns: any) => fns.reduceRight((f: any, g: any) => (...args: any[]) => f(g(...args)));
@Mikhail-MM
Mikhail-MM / cy-intercept.js
Created January 5, 2022 03:47
cy-intercept
cy.request({
url: loginUrl,
method: 'POST',
form: true,
body: {
USER: 'username',
PASSWORD: 'pw',
},
})
.its('allRequestResponses')
@Mikhail-MM
Mikhail-MM / test.spec.tsx
Created January 4, 2022 00:08
testing-fail
import React from 'react';
import LocalLoginForm from './index';
import { mount } from 'enzyme';
import { axe, toHaveNoViolations } from 'jest-axe';
import {
noUserValidationMessage,
noPasswordValidationMessage,
noPolicyNumberValidationMessage,
} from './constants';
@Mikhail-MM
Mikhail-MM / mockedLogin.spec.tsx
Created January 3, 2022 21:29
Mocked Login utils
import axios from 'axios';
import { loginFailedDeterminantText } from './constants';
import {
loginFailedMockResponse,
loginSuccessMockResponse,
} from './__mocks__/loginUtilMocks';
import { loginRequest, validateLoginRequest } from './utils';
jest.mock('axios');
const mockAxios = axios as jest.Mocked<typeof axios>;
@Mikhail-MM
Mikhail-MM / test.spec.tsx
Created December 29, 2021 23:15
auth-test
describe('Test Local Login Utils', async () => {
it("Sending both valid or invalid request to auth endpoint should resolve in a 200 OK response with HTML response data", async () => {
const invalidLoginResponse = await loginRequest(username, 'Incorrect Password');
const validLoginResponse = await loginRequest(username, password);
expect(invalidLoginResponse).toHaveProperty('status');
expect(validLoginResponse).toHaveProperty('status');
expect(invalidLoginResponse).toHaveProperty('data');
expect(validLoginResponse).toHaveProperty('data');
@Mikhail-MM
Mikhail-MM / 15 - Axios - Custom JavaScript Errors.js
Last active May 30, 2023 21:32
Async Error Handling - 15 - Axios - Custom JavaScript Errors
// Custom Errors
class NetworkError extends Error {
constructor({ message, url }) {
super(message);
this.name = 'NetworkError';
this.url = url;
}
}
class APIError extends Error {
@Mikhail-MM
Mikhail-MM / 15 - Axios - Custom Error Types.js
Created September 23, 2021 18:52
Async Error Handling - 15 - Axios - Custom Error Types
/*
Attach any data that you want to your custom errors!
This is similar to when we attached arbitrary properties to the standard JS error.
*/
class NetworkError extends Error {
constructor({ message, url }) {
super(message);
this.name = 'NetworkError';
this.url = url;
@Mikhail-MM
Mikhail-MM / 14 - Returning Errors Instead of Throwing.js
Last active September 23, 2021 22:00
Async Error Handling - 14 - Fetch - Non Throwing Fetch
// Helper for JSON & Plain-Text mixed responses
function processResponseText(responseText) {
try {
return JSON.parse(responseText);
}
catch(err) {
return responseText;
}
}
@Mikhail-MM
Mikhail-MM / 13 - Throwing Errors - Loss of Control.js
Created September 23, 2021 18:04
Async Error Handling - 13 - Throwing Errors - Loss of Control
function processResponseText(responseText) {
try {
return JSON.parse(responseText);
}
catch(err) {
return responseText;
}
}
// This will throw an error.