Created
June 7, 2015 22:56
-
-
Save adamcarr/13f49c8c2d850d298598 to your computer and use it in GitHub Desktop.
Simple example of an annotest unit test using decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The second argument to the ModuleDecorator are mocks that will be provided to the required module if the name matches a require statement.