Reorganize AnnotationSync tests by method

If the tests are grouped according to what class / method / function
they're testing, then it's a lot easier to see what is being tested and
what isn't, and it's easier to find the tests for `foo()` or to know where
to put new tests for `foo()`.

On the other hand when you names tests like
`describe('channel event handlers',` `describe('event handlers',`
`describe('the "loadAnnotations" event',`,
`describe('the "deleteAnnotation" event',` etc then it can be a lot
harder for a reader coming along later to understand how the tests are
organized and how this organization relates to the code itself.

Most of the examples on https://mochajs.org/ use this style of
organizing tests:

    describe('Array', function() {
      describe('#indexOf()', function() {
        it(...
        ...
      });

      describe('#concat()', function () {
        it(...
        ...
      });

      describe('#slice()', function () {
        it(...
        ...
      });

    describe('User', function() {
      describe('#save()', function() {
        it(...

    describe('Connection', function() {
      describe('#find()', function() {
        it(...

This commit reorganizes the AnnotationSync tests along the same lines.

I've also made use of Mocha's `context()` function to group tests
**within a `describe()` for a method** by context. `context()` is just
an alias for `describe()`, but it has different semantics. (This is
also in line with how `context()` is used in the mochajs.org examples).
parent 6a8af948
...@@ -45,8 +45,8 @@ describe('AnnotationSync', function() { ...@@ -45,8 +45,8 @@ describe('AnnotationSync', function() {
sandbox.restore(); sandbox.restore();
}); });
describe('channel event handlers', function() { describe('#constructor', function() {
describe('the "deleteAnnotation" event', function() { context('when "deleteAnnotation" is published', function() {
it('broadcasts the "annotationDeleted" event over the local event bus', function() { it('broadcasts the "annotationDeleted" event over the local event bus', function() {
var ann = {id: 1, $tag: 'tag1'}; var ann = {id: 1, $tag: 'tag1'};
var eventStub = sinon.stub(); var eventStub = sinon.stub();
...@@ -90,7 +90,7 @@ describe('AnnotationSync', function() { ...@@ -90,7 +90,7 @@ describe('AnnotationSync', function() {
}); });
}); });
describe('the "loadAnnotations" event', function() { context('when "loadAnnotations" is published', function() {
it('publishes the "annotationsLoaded" event', function() { it('publishes the "annotationsLoaded" event', function() {
var annotations = [ var annotations = [
{id: 1, $tag: 'tag1'}, {id: 1, $tag: 'tag1'},
...@@ -111,10 +111,8 @@ describe('AnnotationSync', function() { ...@@ -111,10 +111,8 @@ describe('AnnotationSync', function() {
assert.calledWith(loadedStub, annotations); assert.calledWith(loadedStub, annotations);
}); });
}); });
});
describe('event handlers', function() { context('when "beforeAnnotationCreated" is emitted', function() {
describe('the "beforeAnnotationCreated" event', function() {
it('proxies the event over the bridge', function() { it('proxies the event over the bridge', function() {
var ann = {id: 1}; var ann = {id: 1};
createAnnotationSync(); createAnnotationSync();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment