Skip to content

Instantly share code, notes, and snippets.

@asiniy
Created July 4, 2018 11:35
Show Gist options
  • Save asiniy/eb3b7943fca2d5f2fe7e68f367d83f9c to your computer and use it in GitHub Desktop.
Save asiniy/eb3b7943fca2d5f2fe7e68f367d83f9c to your computer and use it in GitHub Desktop.
index.spec.ts // Extending JavaScript with ease (beginner level tutorial)
// tslint:disable:no-expression-statement
import { test } from 'ava';
import objectFetch from './index';
const object = { a: 'b' };
test('returns key if it exists', t => {
t.is(objectFetch(object, 'a'), 'b');
});
test('throws if there is no key', async t => {
const error = await t.throws(() => {
objectFetch(object, 'c');
});
t.is(error.name, 'ReferenceError');
t.is(error.message, 'No such property: c');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment