I have this simple example unit test in Mocha:
const {Builder, By, Key, until} = require('selenium-webdriver')
const chai = require('chai')
chai.should()
var customer
var gigger
var admin
/* eslint-disable no-unused-expressions */
/* globals describe,it */
describe('start all tests', async function () {
describe('create customer user', async function () {
it('creates a user browser', async function () {
customer = await new Builder().forBrowser('chrome').build()
customer.should.not.be.null
this.timeout(5000)
await customer.get('http://www.google.com/ncr')
await customer.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
await customer.wait(until.titleIs('webdriver - Google Search'), 1000)
})
it('creates a gigger browser', async function () {
gigger = await new Builder().forBrowser('chrome').build()
gigger.should.not.be.null
})
it('creates an admin browser', async function () {
admin = await new Builder().forBrowser('chrome').build()
admin.should.not.be.null
})
})
describe('close it all down', async function () {
it('close all browsers down', async function () {
await customer.quit()
await gigger.quit()
await admin.quit()
})
})
})
Everything works fine. BUT! If I un-comment the last describe
:
//describe('close it all down', async function () {
it('close all browsers down', async function () {
await customer.quit()
await gigger.quit()
await admin.quit()
})
//})
What actually happens is that close all browsers down
actually runs straight away.
Is that because describe
functions must contain either all describe
functions, rather than it
as well? If so, this is not documented.
Or, am I missing something?
ADDENDUM: In fact, how does Mocha actually work? I got so used to just typing it, that I never quite got into the actual workings of it. What does Mocha's describe()
actually do? Does it just run the callback? When another nested describe()
is called, how does it figure out that it's a nested one, and which one the parent is? How does it all work, "in general"?