Home Async Jasmine test doesn't invoke beforeEach() before operating
Reply: 0

Async Jasmine test doesn't invoke beforeEach() before operating

user4462 Published in September 19, 2018, 11:30 am

I'm trying to code a test to my client-server modules. I need to run the server before the client is sending its requests, so I'm trying to use beforeEach, but the test fails before the server even started running.

My test:

'use strict';
const cp    = require('child_process');
const ip    = require('my-local-ip');
const utils = require('../util/utils');

describe('Server and client connectivity:', () => {

    let originalTimeout;
    let server;

    beforeEach(function() {
        server = cp.fork('Server/Server');
        originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
        jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

    it('should transfer index.html file to client', (done) => {
        const client = cp.fork('Client/request', ['-t', ip(), '-p', 3300]);
        expect(utils.isFileExistsInDirectory('Client/', 'index.html')).toBe(true);

    afterEach(function() {
        jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;


When I'm running manually first the server, and then the client with these commands, it works perfectly.

In the test sometimes the client request is sent before the server is listening.
How could it happen?
What am I doing wrong?

share|improve this question

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.479903 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO