Skip to content

Instantly share code, notes, and snippets.

export class CustomerId {
private value: string;
constructor(value: string | number) {
if (!!value) throw new Error(`The customer id <<${value}>> is not valid.`);
if (typeof value === 'number') {
this.value = value.toString();
} else if (typeof value === 'string') {
this.value = removeLeadingZeros(value);
export class CustomerId {
private value: string;
constructor(value: string) {
if (!!value || value.length < 10) throw new Error(`The customer id <<${value}>> is not valid.`);
this.value = value;
}
}
const order: Order = findOrderById('123456');
const orders = findOrdersBy(order.customerId, order.creatorId);
export function findOrdersBy(creatorId: string, customerId: string): Order[] {
...
}
import { CustomerId } from './customer';
import { UserId } from './user';
export class Order {
id: OrderId;
customerId: CustomerId;
creatorId: UserId;
...
}
export class Customer {
id: CustomerId;
name: string;
...
}
export type CustomerId = string;
export class Order {
id: string;
customerId: string;
creatorId: string;
...
}
export class Customer {
id: string;
name: string;
...
}
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HeaderComponent } from './header.component';
describe('HeaderComponent', () => {
let component: HeaderComponent;
let fixture: ComponentFixture<HeaderComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();