Skip to content

Instantly share code, notes, and snippets.

@joeeames
joeeames / to-be-a-hero.spec.ts
Created October 9, 2017 13:45
hero matcher
beforeEach(() => {
jasmine.addMatchers({
toBeAHero: (util, customEqualityMatchers) => {
return {
compare: (actual, expected) => {
return {
// heroes are objects that have id, name and strength properties
pass: actual && actual.id && actual.name && actual.strength
};
}
const path = require('path');
const webpack = require('webpack');
const helpers = require('./helpers');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ENV = process.env.NODE_ENV = process.env.ENV = 'development';
module.exports = {
devtool: 'cheap-module-eval-source-map',
/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ var parentJsonpFunction = window["webpackJsonp"];
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, resolves = [], result;
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(installedChunks[chunkId])
@joeeames
joeeames / karma-test-shim.js
Created July 18, 2017 22:27
the final test shim
// /*global jasmine, __karma__, window*/
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.
 
// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
// Error.stackTraceLimit = Infinity; //
 
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
 
var builtPath = '/base/public/app/';
 
@joeeames
joeeames / karma-test-shim.js
Created July 18, 2017 21:57
The template shim from angular.io's testing page
// /*global jasmine, __karma__, window*/
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.
// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
// Error.stackTraceLimit = Infinity; //
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
// builtPaths: root paths for output ("built") files
// get from karma.config.js, then prefix with '/src/' (default is 'app/')
here's the folder structure:
root
karma.conf.js
karma-test-shim.js
public
systemjs.config.js
systemjs-angular-loader.js
main.ts
@joeeames
joeeames / app.module.ts
Created October 5, 2016 16:34
dealing with circular dependencies with ngUpgrade and modules
import { NgModule, forwardRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, NgModel } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { UpgradeAdapter } from '@angular/upgrade';
import { NameParser } from './admin/nameParser';
import { ProfileComponent } from './profile/profile.component';
import { Location, LocationStrategy, HashLocationStrategy, PlatformLocation } from '@angular/common';
export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));
import {Location} from '@angular/common';
import {Component, } from '@angular/core';
import {ComponentFixture, TestBed, fakeAsync, inject, tick} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import {Router} from '@angular/router';
import {RouterTestingModule} from '@angular/router/testing';
@Component({selector: 'root-cmp', template: `
<a routerLink="/simple">click me</a>
// This is really strange. But you need the module when you create
// the upgrade adapter, but you also need the created upgrade adapter
// when creating the Module (see below, the call to upgradeNg1Component)
// so we use a forwardRef, and we have to put the upgradeAdapter and the
// module in the same file
export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));
@NgModule({
@joeeames
joeeames / index.js
Last active September 29, 2015 19:56
module.exports = function() {
console.log('Hello Mars!')
}