Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added some descriptive text to the example project

  • Loading branch information...
commit 46fee2b835c78897f3ab2c44dcff09cbddaa2880 1 parent 8ba73c3
@lukebayes authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 example/test/unit/some_class_test.js
View
38 example/test/unit/some_class_test.js
@@ -1,16 +1,46 @@
var SomeClass = require('some_class').SomeClass;
+// This is an example context for 'SomeClass'.
+// This is the outermost context in the file, but
+// there is no reason a single file can't contain
+// multiple contexts.
context('SomeClass', function() {
+ // This is an example setup method. Any number of
+ // setup methods can be declared and will be called
+ // in the order they are declared. Setup methods
+ // in parent contexts will be called first and
+ // provided a shared 'this' scope.
+ //
+ // The 'this' scope will be unique for each test
+ // method, but shared across it's setup and teardown
+ // methods.
setup(function() {
this.instance = new SomeClass();
});
+ // This method is superfluous, but exists
+ // here as an example. Any number of teardown
+ // handlers can be created and will be called.
+ // Parent context teardowns will be called before
+ // current context teardowns and provided a shared
+ // 'this' scope.
+ teardown(function() {
+ this.instance = null;
+ });
+
+ // This is a simple test method that
+ // relies on the execution of a setup method:
should('be instantiable', function() {
assert.ok(this.instance instanceof SomeClass);
});
+ // This is an asynchronous test method:
+ // Node how we send our custom handler to
+ // this.async, and send it's response to
+ // whatever would normally trigger our custom
+ // handler.
should('do some long task', function() {
var self = this;
this.instance.doSomeLongAsyncTask(10, this.async(function() {
@@ -18,13 +48,21 @@ context('SomeClass', function() {
}));
});
+ // This is a child context, all parent context
+ // setups will be called first.
context('with a custom name', function() {
+ // This is a child setup method. Setups from the
+ // parent context will be called first, but 'this'
+ // is shared.
setup(function() {
assert.ok(this.instance);
this.instance.name = 'foo';
});
+ // This is a child test method that relies on the
+ // fact that the parent context setup was called,
+ // then the child context setup, then this method.
should('accept parent setter', function() {
assert.equal('foo', this.instance.name);
});
Please sign in to comment.
Something went wrong with that request. Please try again.