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)