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

chore(test): clean up mocha tests #5007

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var passingTests = [
'node built/cli.js spec/onPrepareFileConf.js',
'node built/cli.js spec/onPreparePromiseConf.js',
'node built/cli.js spec/onPreparePromiseFileConf.js',
// 'node built/cli.js spec/mochaConf.js',
'node built/cli.js spec/mochaConf.js',
'node built/cli.js spec/withLoginConf.js',
'node built/cli.js spec/suitesConf.js --suite okmany',
'node built/cli.js spec/suitesConf.js --suite okspec',
Expand Down
36 changes: 20 additions & 16 deletions spec/mocha/lib_spec.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
// Use the external Chai As Promised to deal with resolving promises in
// expectations.
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

var expect = chai.expect;
const expect = chai.expect;

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

describe('no protractor at all', function() {
it('should still do normal tests', function() {
describe('no protractor at all', () => {
it('should still do normal tests', () => {
expect(true).to.equal(true);
});
});

describe('protractor library', function() {
it.skip('should be able to skip tests', function() {
describe('protractor library', () => {
it.skip('should be able to skip tests', () => {
expect(true).to.equal(false);
});

it('should expose the correct global variables', function() {
it('should expose the correct global variables', () => {
expect(protractor).to.exist;
expect(browser).to.exist;
expect(by).to.exist;
expect(element).to.exist;
expect($).to.exist;
});

it('should wrap webdriver', function() {
it('should wrap webdriver', async function() {
// Mocha will report the spec as slow if it goes over this time in ms.
this.slow(6000);
browser.get('index.html');

await browser.get('index.html');
expect(browser.getTitle()).to.eventually.equal('My AngularJS App');
});

describe('with async tests', function() {
var finished = false;
describe('with async tests', () => {
let finished = false;

it('should wait for async operations to finish', function() {
browser.get('index.html').then(function() { finished = true; });
it('should wait for async operations to finish', async() => {
await browser.get('index.html');
finished = true;
});

after('verify mocha waited', function() {
if(!finished) { throw new Error('Mocha did not wait for async!'); }
after('verify mocha waited', () => {
if(!finished) {
throw new Error('Mocha did not wait for async!');
}
});
});
});
1 change: 1 addition & 0 deletions spec/mochaConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var env = require('./environment.js');
// A small suite to make sure the mocha framework works.
exports.config = {
seleniumAddress: env.seleniumAddress,
SELENIUM_PROMISE_MANAGER: false,

framework: 'mocha',

Expand Down