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() {
sandbox.restore();
});
describe('channel event handlers', function() {
describe('the "deleteAnnotation" event', function() {
describe('#constructor', function() {
context('when "deleteAnnotation" is published', function() {
it('broadcasts the "annotationDeleted" event over the local event bus', function() {
var ann = {id: 1, $tag: 'tag1'};
var eventStub = sinon.stub();
......@@ -90,7 +90,7 @@ describe('AnnotationSync', function() {
});
});
describe('the "loadAnnotations" event', function() {
context('when "loadAnnotations" is published', function() {
it('publishes the "annotationsLoaded" event', function() {
var annotations = [
{id: 1, $tag: 'tag1'},
......@@ -111,10 +111,8 @@ describe('AnnotationSync', function() {
assert.calledWith(loadedStub, annotations);
});
});
});
describe('event handlers', function() {
describe('the "beforeAnnotationCreated" event', function() {
context('when "beforeAnnotationCreated" is emitted', function() {
it('proxies the event over the bridge', function() {
var ann = {id: 1};
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