For faster navigation, this Iframe is preloading the Wikiwand page for Mocha (фреймворк).

Mocha (фреймворк)

Материал из Википедии — свободной энциклопедии

Mocha
Логотип программы Mocha
Тип JavaScript-фреймворк, автоматизация тестирования
Разработчик Mocha
Написана на JavaScript[2]
Операционная система кроссплатформенность
Первый выпуск 22 ноября 2011
Последняя версия
Репозиторий github.com/mochajs/mocha
Лицензия лицензия MIT[3]
Сайт mochajs.org

Mocha — фреймворк для тестирования на языке JavaScript. Функционирует на основе Node.js, поддерживает работу с браузерами, асинхронное тестирование, отчеты о покрытия продукта тестами, а также работу с любой «ассертной» библиотекой[4].

Библиотеки

[править | править код]

Mocha может работать с большинством популярных «ассертных» библиотек в JavaScript, включая[5]:

  • should.js
  • express.js
  • chai
  • better-assert
  • unexpected
$ npm install -g mocha
$ mkdir test
var assert = require("assert")
describe('Foo', function(){
  describe('#getBar(value)', function(){
    it('should return 100 when value is negative') // placeholder
    it('should return 0 when value is positive', function(){
      assert.equal(0, Foo.getBar(10));
    })
  })
})
$  mocha

1 test complete (1ms)

Для асинхронного тестирования вызывается обратный вызов, и Mocha будет ждать завершения.

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

Примечания

[править | править код]
  1. Release 10.7.3 — 2024.
  2. The mocha Open Source Project on Open Hub: Languages Page — 2006.
  3. The mocha Open Source Project on Open Hub: Licenses Page — 2006.
  4. Mocha - the fun, simple, flexible JavaScript test framework. mochajs.org. Дата обращения: 3 октября 2022. Архивировано 7 декабря 2020 года.
  5. Mocha Wiki (англ.). GitHub. Дата обращения: 3 октября 2022. Архивировано 3 октября 2022 года.
{{bottomLinkPreText}} {{bottomLinkText}}
Mocha (фреймворк)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?