sample test only works when done is passed

1,285 views
Skip to first unread message

Sriram Kota

unread,
Jun 3, 2015, 5:49:57 PM6/3/15
to jasmi...@googlegroups.com

I am just getting started with angular testing with jasmine.

I have the following sample test which only works when i pass 'done'


describe('JavaScript addition operator', function () {
    it('adds two numbers together', function (done) {
        done();
        expect(1 + 2).toEqual(3);
    });
});

if i do not pass done...i get the following error...

"Error: 'expect' was used when there was no current spec, this could be because an asynchronous test timed out"

is this correct? how do i fix it?

npm versions
------------------
karma:                 0.12.35
karma-jasmine :  0.3.5
jasmine            :  2.3.1

os:  OSX yosemite


Gregg Van Hove

unread,
Jun 4, 2015, 11:20:30 PM6/4/15
to jasmi...@googlegroups.com
Calling `done()` indicates to jasmine that you have finished doing everything in your `it`, `beforeEach`, etc and it should move on to the next thing in the queue (or finish the run, as in this case). If you do anything after calling `done()` it will at the very least be connected with a different spec than the one you intended.

Hope this helps,

-Gregg

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages