clinical:verification

v4.0.3Published 8 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

clinical:verification

clinical:verification is a fork and extention of the excellent practicalmeteor:munit package and modified to work with the StarryNight utility and the Clinical Meteor Track. The primary reason for forking, rather than contributing, was to clean up some of the APIs to make them isomorphic with Nightwatch.

Installation

Simply install with the following command:

meteor add clinical:verification

Running Tests

There are two ways of running the verification tests:

# via the tinytest runner
cd myapp
meteor test-packages

# via the nightwatch tinytest pickup
starrynight run-tests --framework tinytest-ci

See the StarryNight TinyTest Walkthrough for more information on how to use the --framework tinytest-ci functionality.

TinyTest API

The default API for a package verification test, looks something like this.

1Tinytest.add('example', function (test) {
2  test.equal(true, true);
3});

The test argument can take any of the following methods:

  • equal(actual, expected, message)
  • notEqual(actual, expected, message)
  • instanceOf(obj, klass)
  • matches(actual, regexp, message)
  • throws(func, expected)
  • isTrue(value, message)
  • isFalse(value, message)
  • isNull(value, message)
  • isNotNull(value, message)
  • isUndefined(value, message)
  • isNaN(value, message)
  • include(object, key)
  • include(string, substring)
  • include(array, value)
  • length(obj, expected_length, message)

Describe/It API

clinical:verification extends the default API with Describe/It syntax.

  • describe(suiteName, function)
  • it(testName, function)

Nested Describes

Describe() can arbitrarily nested; and it() supports Chai Expect syntax.

1describe('top-level describe', function(){
2  describe('nested describe', function() {
3    describe('deep nested describe', function() {
4      it('a test', function () {
5        expect(true).to.be.true;
6      })
7    })
8  })
9});

Server & Client Only Tests

1describe.client('client only test suite', function (){
2  it('runs only in client', function (){
3    expect(Meteor.isClient).to.be.true;
4  });
5  it.server('overrides describe.client and runs only in server', function (){
6    expect(Meteor.isServer).to.be.true;
7  });
8});
9
10describe.server('server only test suite', function (){
11  it('runs only in server', function (){
12    expect(Meteor.isServer).to.be.true;
13  });
14  it.client('overrides describe.server and runs only in client', function (){
15    expect(Meteor.isClient).to.be.true;
16  });
17});
18
19describe('client only and server only tests', function () {
20  it.client('runs only in client', function () {
21    expect(Meteor.isClient).to.be.true;
22  });
23  it.server('runs only in server', function () {
24    expect(Meteor.isServer).to.be.true;
25  });
26});
27

Watchers API

1// Creates a watcher named 'watcherName' for obj.method which you can later easily access by 'Watchers.spyName'
2// @obj [Object] obj and method are optional. If you don't specify them, it will create an anonymous spy function.
3// @method [String] The method of @obj to create a spy for.
4Watchers.create(spyName, obj, method)
5
6// You can just use Watchers.spyName instead of this method.
7Watchers.get(spyName)
8
9// You can just use Watchers.spyName.restore instead of this method.
10Watchers.restore(spyName)
11
12// Restore all watchers created with Watchers.create
13Watchers.restoreAll()
1Watchers.create('log', console, 'log');
2console.log('Hello world');
3expect(Watchers.log).to.have.been.calledWith('Hello world');
4...
5// Later on in your test or test suite tear down
6Watchers.restoreAll();

Stubs API

1// Creates a stub named 'stubName' for obj.method which you can later easily access by 'Stubs.stubName'
2// @obj [Object] obj and method are optional. If you don't specify them, it will create an anonymous stub function.
3// @method [String] The method of @obj to create a stub for.
4Stubs.create(stubName, obj, method)
5
6// You can just use stubs.spyName instead of this method.
7Stubs.get(stubName)
8
9// You can just use stubs.stubName.restore instead of this method.
10Stubs.restore(stubName)
11
12// Restore all stubs created with stubs.create
13Stubs.restoreAll()
1todos = new Mongo.collection('Todos');
2Stubs.create('findOne', todos, 'findOne');
3Stubs.findOne.returns({name: 'My todo'});
4
5// Your test code goes here.
6...
7
8// Later on in your test or test suite tear down
9Stubs.restoreAll();

Testing User Interfaces

1describe('fooTemplate', function(){
2  it.client('should have customizable title', function(client){
3    var card = Blaze.renderWithData(
4    	Template.foo,
5    	{title: "lorem ipsum...", description: "words, words, words..."},
6    	document.body
7  	);
8
9  	expect.element('.foo').to.be.visible;
10  	expect.element('.foo .title').text.to.contain('lorem ipsum');
11
12  	Blaze.remove(card);
13  });
14});
15

Extended Example

1
2describe('suite1', function(){
3  before(function (test){
4    // Let's do 'cleanup' beforeEach too, in case another suite didn't clean up properly
5    watchers.restoreAll();
6    stubs.restoreAll();
7    console.log("I'm beforeAll");
8  });
9  beforeEach(function (test){
10    console.log("I'm beforeEach");
11    watchers.create('log', console, 'log');
12  });
13  afterEach(function (test){
14    watchers.restoreAll();
15    console.log("I'm afterEach");
16  });
17  after(function (test){
18    console.log("I'm afterAll");
19    watchers.restoreAll();
20    stubs.restoreAll();
21  });
22  it('test1', function(test){
23    console.log('Hello world');
24    expect(watchers.log).to.have.been.calledWith('Hello world');
25  })
26});

Contributions

Contributions are more than welcome. Here are some of our contributors:

Changelog

CHANGELOG

License

MIT