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

What is the installation and use of the JavaScript testing framework jasmine

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

Share

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

This article shows you how to install and use the JavaScript testing framework jasmine, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Jasmine is a very popular testing framework that does not rely on any other JavaScript components. It has a clean and clear syntax, so that you can easily write test code.

Download and install Jasmine

Start

Go to the Jasmine website to download the standalone version.

Image

Unpack the jasmine-standalone-xxx.zip, run SpecRunner.html, and you will see the following interface:

Image

Open SpecRunner.html and let's see how it works:

JasmineSpecRunnerv2.4.1

Four core concepts of Jasmine

Suites

Suites can be understood as a set of test cases, created using the global Jasmin function describe. The describe function takes two arguments, a string and a function. The string is the name or title of the Suites (usually describes the test content), and the function is the block of code that implements the Suites.

Specs

Specs can be understood as a test case, created using the global Jasmin function it. Like describe, you accept two parameters, a string and a function, which is the test code to be executed, and the string is the name of the test case. A Spec can contain multiple expectations to test the code.

Expectations

Expectations is created by the expect function. Accept a parameter. In conjunction with Matcher, set the expected value for the test.

Multiple test cases (it) can be written in describe, or grouped (describe), and expectation expressions (expect) and matching judgments (toBe**) can be defined in test cases (it).

Matchers

Matcher implements a comparison between the "expected value" and the "actual value". If the result is true, it passes the test and vice versa. Every matcher can perform negative judgments through not.

The above is how the JavaScript testing framework jasmine is installed and used. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to 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