Node.js
Kaders voor het testen van eenheden
Zoeken…
Mokka synchroon
describe('Suite Name', function() {
describe('#method()', function() {
it('should run without an error', function() {
expect([ 1, 2, 3 ].length).to.be.equal(3)
})
})
})
Mokka asynchroon (terugbellen)
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()
})
})
})
})
Mokka asynchroon (belofte)
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')
})
})
})
})
Mokka Asynchroon (asynchroon / wachten)
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)
})
})
})
Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow