Skip to content

Instantly share code, notes, and snippets.

@joeskeen
joeskeen / jest-testing-errors-with-rxjs.ts
Last active January 25, 2023 14:02
Different ways to use Jest to test error cases in Observable streams
import { Observable, firstValueFrom, timer, isObservable, of } from "rxjs";
import { first, timeout, catchError } from "rxjs/operators";
import { TestScheduler } from "rxjs/testing";
describe("testing error cases in Jest", () => {
describe("with RxJS", () => {
/**
* A test utility function for converting an Observable into a Promise for unit tests
* Uses a TestScheduler to make things like the passage of time (timeouts, debounce, etc.)
* happen instantaneously.
@joeskeen
joeskeen / tests.spec.js
Last active October 1, 2022 22:12
Different ways of handling/expecting errors when testing using Jest (both synchronous and asynchronous)
describe("testing error cases in Jest", () => {
describe("errors (vanilla Jest)", () => {
describe("when thrown synchronously", () => {
function synchronousError() {
throw new Error("");
}
it("should require expect(action).toThrow()", () => {
const action = () => synchronousError();
expect(action).toThrow();
@joeskeen
joeskeen / README.md
Last active September 2, 2022 05:30
ng-conf 2022 Hackathon

ng-conf 2022 Hackathon

Instructions:

  1. ➕ Create your project by clicking this template link: https://github.com/joeskeen/angular-io-game/generate
    (link will be live at 8:00 PM MDT (UTC -6))
  2. 👨🏾‍💻 Make your own IO game based on the seed project
  3. 📝 Submit the game using the form: https://forms.gle/qNms32fdgkyMht2L6
    ⚠️ Submission deadline is 11:00 PM MDT (UTC -6)
  4. 🎮 From 11pm-12am we will all play each other's games and winner will be
@joeskeen
joeskeen / Rules.md
Created September 21, 2020 00:58
Barney Family Traditional Ruleset for Mexican Train Dominoes

Mexican Train Dominoes

Barney Family Traditional Ruleset

Objective

To be the player with the least number of points at the end of the game.

Overview

@joeskeen
joeskeen / things.txt
Created May 7, 2020 01:43
Some prompts for playing Game of Things
Things that squirt
Things you shouldn't throw off a building
Things grownups wish they could still do
Things you shouldn't do In public
Things you shouldn't play catch with
Things that go bad
Things you shouldn't lick
Things you would rather forget
Things you Shouldn't swallow
Things that jiggle
@joeskeen
joeskeen / FindConflictingAppointments.vb
Last active April 25, 2020 19:48
Outlook macro that searches for and displays appointments that conflict with the current appointment
' Searches for and displays appointments that conflict with the current appointment
' If a recurring appointment, the recurrance must be saved before conflicts will be checked
' If a recurring appointment, only checks the next 50 future instances of the recurrance
' Only checks your calendar, not the calendars of other attendees
' Based on macro from https://www.datanumen.com/blogs/quickly-find-appointments-conflicting-specific-appointment-outlook/
Sub FindConflictingAppointments()
Dim objAppointment As AppointmentItem
Dim dStartTime, dEndTime As Date
Dim strFilter As String
Dim objAppointments As Items
@joeskeen
joeskeen / hackathon.md
Last active October 25, 2019 05:00
React Conf 2019 Hackathon

Are you ready to have some fun?

We spend most days working to build good software, to please customers, and to build impressive projects for our resume. Tonight is different. Tonight we are going to the other extreme - writing a completely obnoxious, unintuitive, or otherwise unusable user interface. Inspired by programmers on Reddit, we're going to push the envelope of bad UX in React.

Write the worst form control you can think of! Here are some ideas of controls to mangle:

  • A date picker
  • A US state selector
  • A captcha
@joeskeen
joeskeen / preferences.service.spec.ts
Created October 1, 2019 23:17
A sample spec using a beforeEach block
describe('PreferencesService', () => {
describe('.getPreference', () => {
let service: PreferencesService;
let testValue: Observable<string>;
let result: Observable<string>;
let getItemSpy: jasmine.Spy;
beforeEach(() => {
testValue = scheduled(['test value'], asapScheduler);
getItemSpy = jasmine.createSpy('getItem').and.returnValue(testValue);
@joeskeen
joeskeen / preferences.service.spec.ts
Created October 1, 2019 23:14
A sample spec demonstrating Arrange, Act, Assert
describe('PreferencesService', () => {
describe('.getPreference', () => {
it('should call getItem from LocalStorage', () => {
// Arrange: initialize spy and test subject
const getItemSpy = jasmine.createSpy('getItem');
const service = new PreferencesService({ getItem: getItemSpy } as LocalStorage);
// Act: call getPreference
service.getPreference('test key');
import { Injectable } from '@angular/core';
import { LocalStorage } from '@ngx-pwa/local-storage';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable()
export class PreferencesService {
constructor(private localStorage: LocalStorage) {
}