Skip to content

Instantly share code, notes, and snippets.

View ali-kamalizade's full-sized avatar
🎩
Sunhat

Ali ali-kamalizade

🎩
Sunhat
View GitHub Profile
@ali-kamalizade
ali-kamalizade / mobiflip.e2e-spec.ts
Created May 26, 2018 23:26
Sample e2e test with better-protractor
import {} from "protractor";
import {BetterProtractorService} from "better-protractor";
const service: BetterProtractorService = new BetterProtractorService();
describe('Mobiflip', () => {
it('should navigate to Mobiflip page', async() => {
service.disableAngular();
service.navigateToRoute('https://mobiflip.de');
service.pauseBrowserTemporarily(500);
@ali-kamalizade
ali-kamalizade / healthcheck.js
Last active September 18, 2024 14:57
A sample implementation of a health check endpoint for Node.js using Express
// app.js: register the route. In our case, we don't want authorization for this route
app.use('/healthcheck', require('./routes/healthcheck.routes'));
// healthcheck.routes.js: return a 2xx response when your server is healthy, else send a 5xx response
import express from 'express';
const router = express.Router({});
router.get('/', async (_req, res, _next) => {
// optional: add further things to check (e.g. connecting to dababase)
@ali-kamalizade
ali-kamalizade / json-form-control.stories.ts
Last active February 24, 2020 20:37
Custom Angular Form Control in Storybook
// ...
storiesOf('Forms|JsonFormControlComponent', module)
.addDecorator(withKnobs) // optional: requires https://www.npmjs.com/package/@storybook/addon-knobs to be installed
.addDecorator(moduleMetadata({
imports: [FormsModule],
declarations: [JsonFormControlComponent] // the component we want to test
}))
.add('using an object', () => ({
component: JsonFormControlComponent, // if you want to have control over the template, you should use "template" instead
@ali-kamalizade
ali-kamalizade / json-form-control.component.spec.ts
Last active February 21, 2020 11:19
Testing a custom Angular Form Control with Jest / Jasmine
// ...
describe('JsonFormControlComponent', () => {
let fixture: ComponentFixture < JsonFormControlComponent > ;
let emitValueSpy: jasmine.Spy;
beforeEach(() =>
TestBed.configureTestingModule({
declarations: [JsonFormControlComponent], // the component we want to test
schemas: [NO_ERRORS_SCHEMA] // optional: ignore other custom elements
const fs = require('fs');
function readCsvFile(csvFilePath) {
const csvFileContent = (await fs.readFile(csvFilePath)).toString();
return parse(csvFileContent, {skipEmptyLines: true, header: true});
}
readCsvFile('some-path');
@ali-kamalizade
ali-kamalizade / on-push-change-detection.helper.ts
Last active February 17, 2022 17:15
A function which can be used in Angular component tests to trigger change detection for components using OnPush strategy.
/**
* Changes in components using OnPush strategy are only applied once when calling .detectChanges(),
* This function solves this issue.
*/
export async function runOnPushChangeDetection(fixture: ComponentFixture<any>): Promise<void> {
const changeDetectorRef = fixture.debugElement.injector.get<ChangeDetectorRef>(ChangeDetectorRef);
changeDetectorRef.detectChanges();
return fixture.whenStable();
}
@ali-kamalizade
ali-kamalizade / .gitlab-ci.yml
Last active August 23, 2020 13:44
A sample GitLab CI configuration file for building, testing and deploying a JavaScript based project to Heroku
# This file is a template, and might need editing before it works on your project.
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
image: node:12.10.0
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- node_modules/
@ali-kamalizade
ali-kamalizade / table.html
Last active September 21, 2023 12:55
HTML5 table with sticky table headers in supported browsers. Using bulma.css for styling
<main>
<table class="table is-fullwidth">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Job</th>
<th>Color</th>
<th>URL</th>
</tr>
@ali-kamalizade
ali-kamalizade / ClassWithLombok.java
Last active December 5, 2020 20:52
A sample Java class which uses annotations provided by Project Lombok
package net.example.demo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@ali-kamalizade
ali-kamalizade / expectations.spec.ts
Created January 21, 2021 20:45
An example how to use different testing expectation helpers provided by both Jest and Jasmine.
describe('Jasmine & Jest expectations', () => {
it('can match anything if we do not care for specific parameters', () => {
const spyTrackEvent = spyOn(loginService, 'trackUserLoginEvent').and.callThrough();
loginService.loginUser('[email protected]', 'justcoderthings');
// we expect that the spied function has been called with 3 parameters: a number, the string "2021-01-21" and anything
expect(spyTrackEvent).toHaveBeenCalledWith(jasmine.any(Number), '2021-01-21', jasmine.anything());
});
it('can match partial strings (regex)', () => {