question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

app.stop() throwing errors with Jasmine when all windows are manually closed

See original GitHub issue

I am trying to test to make sure the window is closed properly because I implement some logic in the onbeforeunload event and I want to ensure that it is not failing.

If the window closes correctly, I receive the following error: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.. The error is happening because app.stop() does not seem to be returning its promise when all windows are closed so done() was never called. If I change the line that says app.stop().then(done) to done() then the test passes but the app never quits in the background and the test suite will not return until the user kills it. Also if I change app.quitTimeout to 2000 ms then the test passes but the app doesn’t quit.

I am using OS X El Capitan, jasmine 2.3.2, and spectron 3.3.0

    it('should close the window', (done) => {
        app.start().then(() => {
            app.browserWindow.close().then(()=> {
                app.client.getWindowCount().then((count) => {
                    expect(count).toEqual(0);
                    app.stop().then(done);
                });
            });
        });
    });

Just for sanity, my test case checking if a window is created passes and quits the app as expected without error.

    it('should open a new window', (done) => {
        app.start().then(() =>{
            app.client.getWindowCount().then((count) => {
                expect(count).toEqual(2); //webviews are also counted here
                app.stop().then(done);
            });
        });
    });

Any thoughts/suggestions?

I apologize in advance if this is very simple and going right over my head.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:13

github_iconTop GitHub Comments

2reactions
Mercieralcommented, Aug 3, 2016
 it('should close the window', (done) => {
        app.mainProcess.pid().then((pid) => {
            app.browserWindow.close().then(()=> {
                app.client.getWindowCount().then((count) => {
                    expect(count).toEqual(0);
                    process.kill(pid);
                    done();
                });
            });
        });
    });

Closes the running windowless application as expected, thanks! However my test suite is still hanging after all tests are run, even with no running instances of electron. I believe this specific problem may be related to jasmine-node however as it seems others have had similar problems.

1reaction
sla89commented, Jun 14, 2017

I have the same issue on Windows but without Jasmine. app.stop() does not close the window. Would be great if this can be fixed. At the moment I am using the workaround proposed by @danielwestendorf. Thanks for that!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - app.stop() throwing errors with Jasmine when all ...
app.stop() throwing errors with Jasmine when all windows are manually closed ... I am trying to test to make sure the window is...
Read more >
Karma - Chrome failed 2 times (cannot start). Giving up
I've been trying to run my tests using karma-chrome-launcher, but everytime I run my tests it throws this error: INFO [launcher]: Starting browser...
Read more >
An Introduction to Jasmine Unit Testing - freeCodeCamp
Jasmine is the most popular JS library for unit testing web apps. In this tutorial, designed for beginners, we'll present you with a...
Read more >
Faking dependencies (Mocking) - Testing Angular
In our unit test, we do not want the Service to make any HTTP requests. We pass in a Jasmine spy as replacement...
Read more >
Component testing scenarios - Angular
toBlob() , an "Unknown macroTask scheduled in fake async test" error is thrown. src/app/shared/canvas.component.spec.ts ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found