Rails 5 Test prescriptions 10th unit_testing JavaScript (new tool, learn curve too steep, pass)

Source: Internet
Author: User

The unit test of JS is a big problem. The authors believe that Ruby's testing tools are more flexible than JS's test tools.

Most JS code is ultimately about responding to user behavior and changing elements in the DOM

There are no javascript points of knowledge. The first two sections have several new test tools, and a lot of configuration, temporary pass.

    • Setup JS unit-tests
    • Writing a Sample test
    • Tdd in Js
    • Jasmine Matchers
    • Testing Ajax Calls
    • Using Testdouble.js
    • Connecting the JS to the server code

Setting up JavaScript Unit Tests

The configuration of the Webpack is complex, and while the rails team has made improvements, it is sometimes necessary to dig into the details.

This chapter uses:

Karma Test Runner: Run from the command line, perform the test, and good compatibility with the microblogging window

Jasmine: A tool for testing, the author likes its syntax.

Testdouble Package:

Command: Load the relevant module:

Yarn Add Jasmine Jasmine-core Karma Karma-chrome-launcher Karma-jasmine karma-mocha-reporter karma-sourcemap-loader karma-webpack Testdouble testdouble-jasmine --dev

Explain:

Use Yarn Package Manager to manage the standalone JS. Use yarn to load these modules.

The --dev command adds these modules to the separate section in Package.json. (that is, these modules are used only in development environments, and are used for testing) tags are "devdependencies"

"Devdependencies": {" Jasmine": "^3.1.0", libraries that write code" Jasmine-core": "^3.1.0", libraries that write code" Karma": "^2.0.2", Command-Line Program" karma-chrome-launcher": "^2.2.0", let Karma run the test in Chrome" karma-jasmine": "^1.1.2", interface" karma-mocha-reporter": "^2.2.5"," Karma-sourcemap-loader": "^0.3.7"," karma-webpack": "^3.0.0", let karma use Webpack" testdouble": "^3.8.1", Mock Object Package" testdouble-jasmine": "^0.2.1", the integration of both. " webpack-dev-server": "2.11.2 "  }

Run again:

$ yarn Global add KARMA-CLI

So the module is already loaded.

Rails 5 Test prescriptions 10th unit_testing JavaScript (new tool, learn curve too steep, pass)

Related Article

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.