< 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
4. Installing 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