Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and test mocha

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to install and test mocha", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to install and test mocha" article.

What is TDD:TDD:Test driven devlement, test-driven development, is not only a core practice and technology in agile development, but also a design methodology. The principle of TDD is to write the unit test case code before developing the functional code, and the test code determines what product code needs to be written. What is mocha:mocha is a unit testing framework for JavaScript that can be run either in a browser environment or in a Node.js environment. Install mocha:

1. Create a project.

two。 Run:

# initialize npm init#, install mochanpm i mocha chai-D, write business code:

Write math.js to simulate business code

Function add (XMagol y) {return Xeroy;} function multiply (XJO y) {return XY;} module.exports= {add,multiply} write test code: / / import the math.jsvar math=require (".. / math") that you just wrote; / / import the assertion var assert= require ("assert") / / describe the test file describe ('test math.js',function () {/ / describe the test method describe (' test method add',function () {/ / mocha) provides it methods, called test cases, indicating a single test / / We can write multiple test cases of a method to test the situation in different situations. It ('10 minutes 1 minutes function () {/ / asserts 10 minutes 1 minutes 11 assert.equal (math.add (10 minutes 1), 11);}); / / Test failed / / Test 10 minutes 2 Assertion 10-2-9 it ("10-2", function () {assert.equal (math.add (10-2), 9)}); describe ("test method multiply", function () {/ / test 5-2 it ('5-2) assert.equal (math.multiply (5-2), 10) })});}) configure package.json:

Directly use the mocha test to display on the terminal

"scripts": {"test": "mocha"} run the test: the above npm test is about "how to install and test mocha". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report