Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 738f232

Browse files
committed
chore(test): clean up mocha tests
- this.slow does not appear to be part of the mocha framework or we are not correctly exposing it. Removed since it was causing errors. - moved tests to be async / await where appropriate.
1 parent 4e149af commit 738f232

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

scripts/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var passingTests = [
1919
'node built/cli.js spec/onPrepareFileConf.js',
2020
'node built/cli.js spec/onPreparePromiseConf.js',
2121
'node built/cli.js spec/onPreparePromiseFileConf.js',
22-
// 'node built/cli.js spec/mochaConf.js',
22+
'node built/cli.js spec/mochaConf.js',
2323
// 'node built/cli.js spec/withLoginConf.js',
2424
'node built/cli.js spec/suitesConf.js --suite okmany',
2525
'node built/cli.js spec/suitesConf.js --suite okspec',

spec/mocha/lib_spec.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,53 @@
11
// Use the external Chai As Promised to deal with resolving promises in
22
// expectations.
3-
var chai = require('chai');
4-
var chaiAsPromised = require('chai-as-promised');
3+
const chai = require('chai');
4+
const chaiAsPromised = require('chai-as-promised');
55
chai.use(chaiAsPromised);
66

7-
var expect = chai.expect;
7+
const expect = chai.expect;
88

99
// Chai's expect().to.exist style makes default jshint unhappy.
1010
// jshint expr:true
1111

12-
describe('no protractor at all', function() {
13-
it('should still do normal tests', function() {
12+
describe('no protractor at all', () => {
13+
it('should still do normal tests', () => {
1414
expect(true).to.equal(true);
1515
});
1616
});
1717

18-
describe('protractor library', function() {
19-
it.skip('should be able to skip tests', function() {
18+
describe('protractor library', () => {
19+
it.skip('should be able to skip tests', () => {
2020
expect(true).to.equal(false);
2121
});
2222

23-
it('should expose the correct global variables', function() {
23+
it('should expose the correct global variables', () => {
2424
expect(protractor).to.exist;
2525
expect(browser).to.exist;
2626
expect(by).to.exist;
2727
expect(element).to.exist;
2828
expect($).to.exist;
2929
});
3030

31-
it('should wrap webdriver', function() {
31+
it('should wrap webdriver', async function() {
3232
// Mocha will report the spec as slow if it goes over this time in ms.
3333
this.slow(6000);
34-
browser.get('index.html');
34+
35+
await browser.get('index.html');
3536
expect(browser.getTitle()).to.eventually.equal('My AngularJS App');
3637
});
3738

38-
describe('with async tests', function() {
39-
var finished = false;
39+
describe('with async tests', () => {
40+
let finished = false;
4041

41-
it('should wait for async operations to finish', function() {
42-
browser.get('index.html').then(function() { finished = true; });
42+
it('should wait for async operations to finish', async() => {
43+
await browser.get('index.html');
44+
finished = true;
4345
});
4446

45-
after('verify mocha waited', function() {
46-
if(!finished) { throw new Error('Mocha did not wait for async!'); }
47+
after('verify mocha waited', () => {
48+
if(!finished) {
49+
throw new Error('Mocha did not wait for async!');
50+
}
4751
});
4852
});
4953
});

spec/mochaConf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var env = require('./environment.js');
33
// A small suite to make sure the mocha framework works.
44
exports.config = {
55
seleniumAddress: env.seleniumAddress,
6+
SELENIUM_PROMISE_MANAGER: false,
67

78
framework: 'mocha',
89

0 commit comments

Comments
 (0)