Skip to content

Instantly share code, notes, and snippets.

@adamcarr
Created June 7, 2015 22:56
Show Gist options
  • Save adamcarr/13f49c8c2d850d298598 to your computer and use it in GitHub Desktop.
Save adamcarr/13f49c8c2d850d298598 to your computer and use it in GitHub Desktop.
Simple example of an annotest unit test using decorators
/// <reference path="../typings/tsd.d.ts" />
import * as assert from 'assert';
import annotest from '../index';
import IPerson from './IPerson';
@annotest.ModuleDecorator('Person tests', {'./IsEighteenOrOlder': {default:(age: number) => age > 19}})
class MyCustomTest {
@annotest.TestMethodDecorator('Testing person constructor')
static testConstructor() {
var Person: IPerson = require('./Person')['default'];
var name = 'Adam';
var age = 34;
var person = new Person(name, age);
assert.equal(person.name, name);
assert.equal(person.age, age, 'Ages should match');
}
@annotest.TestMethodDecorator('Testing person canVote')
static testCanVote() {
var Person: IPerson = require('./Person')['default'];
var name = 'Adam';
var age = 18;
var person = new Person(name, age);
assert(person.canVote, `Person is ${person.age} and is 18 or older and should be able to vote.`);
}
}
export default MyCustomTest;
@adamcarr
Copy link
Author

adamcarr commented Jun 7, 2015

The second argument to the ModuleDecorator are mocks that will be provided to the required module if the name matches a require statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment