Skip to content

Instantly share code, notes, and snippets.

View jkyoutsey's full-sized avatar
📐

Jared Youtsey jkyoutsey

📐
View GitHub Profile
@jkyoutsey
jkyoutsey / my-parent-component.html
Last active January 7, 2019 21:53
Angular Unit Testing sample template with property and event handler bindings
<my-child [item]="items"
(clicked)="onClick($event)">
</my-child>
@jkyoutsey
jkyoutsey / unit-test-with-NES.spec.ts
Last active January 7, 2019 21:54
Angular Unit Testing NO_ERRORS_SCHEMA spec file
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyParentComponent ],
schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents();
}));
@jkyoutsey
jkyoutsey / d.component.scss
Last active January 3, 2019 19:44
CSS Grid Smart Component SCSS fixed
:host {
/*
* Ignore this smart-component wrapper, allowing us to position dumb child components
* in the global CSS Grid layout!
* Not supported in IE or Edge at all!
* https: //caniuse.com/#search=display%3A%20contents
*/
display: contents;
}
@jkyoutsey
jkyoutsey / d.component.html
Created January 3, 2019 19:37
CSS Grid Smart Component
<app-a></app-a>
<app-b></app-b>
@jkyoutsey
jkyoutsey / app.component.scss
Created January 3, 2019 19:33
CSS Grid app.component.scss
app-c {
grid-area: purple;
}
@jkyoutsey
jkyoutsey / app.component.html
Created January 3, 2019 19:31
CSS Grid app.component.html
<app-d></app-d>
<app-c></app-c>
@jkyoutsey
jkyoutsey / styles.scss
Last active January 3, 2019 19:30
CSS Grid for Angular global styles
app-root {
padding: 1em;
box-sizing: border-box;
height: 100vh;
width: 100vw;
display: grid;
grid-gap: 1em;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr;
grid-template-areas: 'blue green purple';
@jkyoutsey
jkyoutsey / can-deactivate-guard.service.spec-tests.ts
Created August 9, 2018 03:34
Angular CanDeactivate Guard Unit Tests
it('can route if unguarded', () => {
// Mock GuardedComponent.isGuarded = false, which returns true from canActivate()
mockComponent.returnValue = true;
expect(service.canDeactivate(mockComponent)).toBeTruthy();
});
it('will route if guarded and user accepted the dialog', () => {
// Mock the behavior of the GuardedComponent:
const subject$ = new Subject<boolean>();
mockComponent.returnValue = subject$.asObservable();
@jkyoutsey
jkyoutsey / can-deactivate-guard.service.spec-config-excerpt.ts
Created August 9, 2018 03:31
Angular CanDeactivate Guard Unit Test Configuration
describe('CanDeactivateGuardService', () => {
let mockComponent: MockComponent;
let service: CanDeactivateGuardService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
CanDeactivateGuardService,
MockComponent
]
@jkyoutsey
jkyoutsey / can-deactivate-guard.service.ts
Created August 9, 2018 03:22
Angular CanDeactivate Guard Service
import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { GuardedComponent } from './guarded/guarded.component';
import { CanDeactivateGuarded } from './can-deactivate-guarded';
@Injectable({
providedIn: 'root'
})
export class CanDeactivateGuardService implements CanDeactivate<CanDeactivateGuarded> {
canDeactivate(component: CanDeactivateGuarded) {