Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Mocha (JavaScript framework)

From Wikipedia, the free encyclopedia
JavaScript test framework running on Node.js
For other uses, seeMocha.
This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages)
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Mocha" JavaScript framework – news ·newspapers ·books ·scholar ·JSTOR
(February 2022) (Learn how and when to remove this message)
The topic of this articlemay not meet Wikipedia'snotability guidelines for products and services. Please help to demonstrate the notability of the topic by citingreliable secondary sources that areindependent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to bemerged,redirected, ordeleted.
Find sources: "Mocha" JavaScript framework – news ·newspapers ·books ·scholar ·JSTOR
(August 2014) (Learn how and when to remove this message)
(Learn how and when to remove this message)
Mocha
Developer(s)OpenJS Foundation
Initial releaseNovember 22, 2011 (2011-11-22)
Stable release
11.7.1[1] Edit this on Wikidata / 24 June 2025; 16 days ago (24 June 2025)
Repositorygithub.com/mochajs/mocha
Written inJavaScript
PlatformNode.js
TypeTest automation framework
LicenseMIT
Websitemochajs.org

Mocha is aJavaScript test framework forNode.js programs, featuring browser support, asynchronous testing, test coverage reports, and use of any assertion library.[2]

Assertion libraries

[edit]

Mocha can be used with most JavaScript assertion libraries, including:

  • should.js
  • express.js
  • chai
  • better-assert
  • unexpected

Usage and examples

[edit]
$npminstall-gmocha$mkdirtest$$EDITORtest/test.js# or open with your favorite editor
varassert=require("assert")describe('Foo',function(){describe('#getBar(value)',function(){it('should return 100 when value is negative')// placeholderit('should return 0 when value is positive',function(){assert.equal(0,Foo.getBar(10));})})})
$mocha.1 test complete (1ms)


Forasynchronous testing, invoke the callback, and Mocha will wait for completion.

describe('Foo',function(){describe('#bar()',function(){it('should work without error',function(done){varfoo=newFoo(128);foo.bar(done);})})})

See also

[edit]

References

[edit]
  1. ^"Release 11.7.1". 24 June 2025. Retrieved24 June 2025.
  2. ^"Mocha - the fun, simple, flexible JavaScript test framework".mochajs.org.

External links

[edit]
Code analysis
Supersets
Transpilers
Concepts
Debuggers
Documentation generators
Editors (comparison)
Engines
Frameworks
Relatedtechnologies
Package managers
Module bundlers
Server-side
Unit testing frameworks (list)
People
Retrieved from "https://en.wikipedia.org/w/index.php?title=Mocha_(JavaScript_framework)&oldid=1283269370"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp