I am trying to write tests for electron using spectron.
This is my code.
describe ('Application launch', function(done) {
this.timeout(30000);
const app = new Application({
path: electronBinary,
args: [baseDir],
});
before(() => app.start());
after(() => app.stop());
it('shows an initial window', async () => {
await app.client.waitUntilWindowLoaded();
const count = await app.client.getwindowcount();
assert.equal(count,1);
});
});
However, When I run npm test
The error I get is
1) Application launch "before all" hook:
Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
2) Application launch "after all" hook:
Error: Application not running
at Application.stop (node_modules\spectron\lib\application.js:58:48)
at Context.after (test\spec.js:19:19)
Do I need to add any functions to the existing hooks?
I am trying to write tests for electron using spectron.
This is my code.
describe ('Application launch', function(done) {
this.timeout(30000);
const app = new Application({
path: electronBinary,
args: [baseDir],
});
before(() => app.start());
after(() => app.stop());
it('shows an initial window', async () => {
await app.client.waitUntilWindowLoaded();
const count = await app.client.getwindowcount();
assert.equal(count,1);
});
});
However, When I run npm test
The error I get is
1) Application launch "before all" hook:
Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
2) Application launch "after all" hook:
Error: Application not running
at Application.stop (node_modules\spectron\lib\application.js:58:48)
at Context.after (test\spec.js:19:19)
Do I need to add any functions to the existing hooks?
Share Improve this question asked Jan 21, 2019 at 12:55 EmjeyEmjey 2,0633 gold badges21 silver badges35 bronze badges2 Answers
Reset to default 1It appears to be happening in your before all
method. Notice that your error says 1) Application launch "before all" hook:
.
So your actual test function looks fine to me. And I don't see a beforeAll
anywhere in this example code so I would say there is one of two possible problems.
- There is a
beforeAll
method with an issue somewhere not in this code sample. - The
before
hook shown here is returning a non-promise object.
In your code you are using a lambda function to do the work of before but if app.start()
is returning an object which is not a promise then that would be your issue. Try refactoring it more like this:
before(() => {
app.start()
})
If your app.start()
function is asynchronous you may need to pass the done handler into it:
before((done) => {
app.start(done)
})
Or possibly convert your app.start()
function to return a promise which should resolve it. You may need to add async () => await app.start()
but I don't think that would be necessary for a single expression like this.
You didn't use "done" as a callback in your it-function. You also don't have to use done in the describe callback. Also, since done() already makes your code asynchronous, you don't have to use the async keyword. My solution:
describe ('Application launch', function() {
this.timeout(30000);
const app = new Application({
path: electronBinary,
args: [baseDir],
});
before(() => app.start());
after(() => app.stop());
it('shows an initial window', (done) => {
await app.client.waitUntilWindowLoaded();
const count = app.client.getwindowcount();
assert.equal(count,1);
done();
});
});
Hope it helps!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745365651a4624564.html
评论列表(0条)