Use Karma test to write a small demo (arguments for example)

Source: Internet
Author: User

Some people say that front-end automated testing is very difficult, and I think it does. In the project, I personally do not feel comfortable writing tests, or to manually test. However, when we write the demo, we can use the automated test at all times.

Traditional Demo

1, create a new HTML

2, write JS script

3, run HTML

Usually write demo, The big guys are probably this step, in fact, we can use Karma automation this process.

Automated demo (using Karma)

Assuming you have installed the karma, if not, please see my blog Karma Unit test get started

1, running in root directory

Karma Init

All the way to the space select default, at what's the location of your source and test files? This entry *.js, other default

2, create a new JS file in the root directory demo.js

such as netizens an example:

function F (A, B, c) {    alert (arguments.length);    // Result: "2"    A = +;    Alert (arguments[0]);       // Result: "    Arguments[0] = "Qqyumidi";    alert (a);                   // Result: "Qqyumidi"    alert (c);                  // result: "Undefined"    c =;    Alert (arguments[2]);       // result: "Undefined" }f (1, 2);

3, run

Karma Start

At the command line you can see the results of the operation:

Feeling trouble?

This is my teaching, so write more wordy, I myself in the test when all kinds of quick and good!

Why don't you use Jasmine's grammar?

Of course, those describe grammar can be used, this example is just for teaching, so try to avoid interfering factors.

Use Karma test to write a small demo (arguments for example)

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.