Use Karma, Jasmine to do front-end unit testing

Source: Internet
Author: User

< a > Using technology
    • Karma

    • Jasmine

    • Karma-coverage


< two > Install plug-in 1.nodejs 2. Install Karma
    • NPM install-g Karma

    • NPM install-g KARMA-CLI

3. Installing Jasmine
    • NPM Install-g Jasmine

4. Installing Karma-coverage
    • NPM install-g Karma-coverage


< three > Run a Program 1. Project directory structure:

2.add.js file
function Add (A, B) {return a + B;}
3.add-test.js
Describe ("My great and huge math Lib", function () {It ("should perfectly complete complex addition", function () {VA    R result = Add (3, 5);  Expect (result). toequal (8); });});
4.conf file

You can do this, under the Karma-my-proj directory

Karma Init pro-conf.js

5. Start the program

Karma Start Pro-conf.js

According to the prompts, choose JS directory, chrome, jasmine, etc.

6. You can also edit conf.js as follows:

<1>.files

List of files/patterns to load in the browser files: [' js/**/*.js ', ' test/**/*.js '],

<2>.coverage

Test results reporter to use//possible values: ' dots ', ' progress '//Available Reporters:https://npmjs.org/bro Wse/keyword/karma-reporter reporters: [' progress ', ' coverage '], preprocessors: {' js/**/*.js ': ' Coverage '}, Covera Gereporter: {type: ' html ', dir: ' coverage/'},

< four > operation result:
1. Terminal:

2. Browser

3. Coverage report:


Use Karma, Jasmine to do front-end unit testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.