RIP
Tutorial
Tags
Topics
Examples
eBooks
Tutorial by Examples
Mocha synchronous
describe('Suite Name', function() { describe('#method()', function() { it('should run without an error', function() { expect([ 1, 2, 3 ].length).to.be.equal(3) }) }) })
Mocha asynchronous (callback)
var expect = require("chai").expect; describe('Suite Name', function() { describe('#method()', function() { it('should run without an error', function(done) { testSomething(err => { expect(err).to.not.be.equal(null) done() }) }) }) }) ...
Mocha asynchronous (Promise)
describe('Suite Name', function() { describe('#method()', function() { it('should run without an error', function() { return doSomething().then(result => { expect(result).to.be.equal('hello world') }) }) }) })
Mocha Asynchronous (async/await)
const { expect } = require('chai') describe('Suite Name', function() { describe('#method()', function() { it('should run without an error', async function() { const result = await answerToTheUltimateQuestion() expect(result).to.be.equal(42) }) }) })
Page 1 of 1
1
Cookie
This website stores cookies on your computer.
We use cookies to enhance your experience on our website and deliver personalized content.
For more details on our cookie usage, please review our
Cookie Policy
and
Privacy Policy
Accept all Cookies
Leave this website