Help writing specs, timeout error on activation


#1

I need some help with writing of specs. Unit testing is an area I am not really skilled at.

Here is my spec.js that is failing ( the view spec is simply empty):

'use babel';

import Scaffolding from '../lib/scaffolding';

describe('Scaffolding', () => {
    let workspaceElement, scaffolding, activationPromise;

    describe('Before activating package', () => {
        it('Should not exist yet', () => {
            workspaceElement = atom.views.getView(atom.workspace);
            jasmine.attachToDOM(workspaceElement);

            expect(workspaceElement.querySelector('.scaffolding')).not.toExist();
        });
    });

    beforeEach(() => {
        workspaceElement = atom.views.getView(atom.workspace);
        jasmine.attachToDOM(workspaceElement);

        atom.commands.dispatch(workspaceElement, "scaffolding:test");

        waitsForPromise(() => {
            return atom.packages.activatePackage("scaffolding");
        });

    });

    describe('Running command scaffolding:toggle', () => {

        it('Should be visible after toggling', () => {

            expect(workspaceElement.querySelector('.scaffolding')).toExist();
            expect(workspaceElement.querySelector('.scaffolding')).toBeVisible();

        });

        it('Should not be visible after toggling twice', () => {
            atom.commands.dispatch(workspaceElement, "scaffolding:toggle");

            expect(workspaceElement.querySelector('.scaffolding')).toExist();
            expect(workspaceElement.querySelector('.scaffolding')).not.toBeVisible();
        });
    });
});

When I run Atom test package specs I get this error:

Scaffolding
  Before activating package
    it Should not exist yet
    timeout: timed out after 5000 msec waiting for promise to be resolved or rejected
...

I am currently running the Atom beta from the AUR repository on Manjaro Linux and thought the problem could be caused by using the unofficial repository. However, even when running the spec in Travis CI, I get this error.

Package can be found here:

The testing branch is where I am trying to get specs working for the newer version.


#2

The scope in which you place the beforeEach is more important than the order in which it appears. Since your beforeEach is in the outer scope to describe('Before activating package', the beforeEach is executed before all of the specs inside that describe block. If you want to have that beforeEach only execute for certain specs, it needs to be in a separate describe block. I would recommend describe('After activating package'.


#3

Ok, so I fixed that first issue I did not realise, by pushing the “Before activation” test and wrap the rest inside it like so:

'use babel';

import Scaffolding from '../lib/scaffolding';

describe('Scaffolding', () => {
    describe('Before activation', () => {
        it('Should not exist yet', () => {
            workspaceElement = atom.views.getView(atom.workspace);
            jasmine.attachToDOM(workspaceElement);

            expect(workspaceElement.querySelector('.scaffolding')).not.toExist();
        });
    });

    describe('Scaffolding command tests', () => {
        let workspaceElement, scaffolding, activationPromise;

        beforeEach(() => {
            workspaceElement = atom.views.getView(atom.workspace);
            jasmine.attachToDOM(workspaceElement);

            atom.commands.dispatch(workspaceElement, "scaffolding:test");

            waitsForPromise(() => {
                return atom.packages.activatePackage("scaffolding");
            });

        });

        describe('Running command scaffolding:toggle', () => {

            it('Should be visible after toggling', () => {

                expect(workspaceElement.querySelector('.scaffolding')).toExist();
                expect(workspaceElement.querySelector('.scaffolding')).toBeVisible();

            });

            it('Should not be visible after toggling twice', () => {
                atom.commands.dispatch(workspaceElement, "scaffolding:toggle");

                expect(workspaceElement.querySelector('.scaffolding')).toExist();
                expect(workspaceElement.querySelector('.scaffolding')).not.toBeVisible();
            });
        });
    });
});

But I still get the timeout error for both tests inside the “scaffolding:toggle”


#4

See my posts in this other topic for a step-by-step guide on how to write specs and handle activation: