Forráskód Böngészése

提交单元测试

olym 7 éve
szülő
commit
882df0fee7
2 módosított fájl, 17 hozzáadás és 1 törlés
  1. 1 1
      package.json
  2. 16 0
      test/app/lib/js_validator.test.js

+ 1 - 1
package.json

@@ -33,7 +33,7 @@
   "scripts": {
     "start": "egg-scripts start --daemon",
     "stop": "egg-scripts stop",
-    "dev": "set EGG_SERVER_ENV=local&&egg-bin dev --port 7002",
+    "dev": "egg-bin dev --port 7002",
     "dev-local": "set EGG_SERVER_ENV=qa&&egg-bin dev --port 7002",
     "dev-qa": "set EGG_SERVER_ENV=qa&&egg-bin dev --port 7002",
     "test": "npm run lint -- --fix && npm run test-local",

+ 16 - 0
test/app/lib/js_validator.test.js

@@ -40,4 +40,20 @@ describe('test/app/lib/js_validator.test.js', () => {
         assert(convertRule === expectRule);
     });
 
+    it('test js validator', function* () {
+        const ctx = app.mockContext();
+        const jsValidator = new JsValidator(ctx);
+
+        const rule = {
+            username: { type: 'string', required: true, allowEmpty: false, min: 4, max: 10 },
+            group_id: { type: 'integer', required: true, allowEmpty: false, min: 4, max: 10 },
+            password: { type: 'password', required: true, allowEmpty: false, min: 4 },
+            confirm_password: { type: 'password', required: true, allowEmpty: false, min: 4, compare: 'password' },
+            ip: { type: 'ip', allowEmpty: false },
+            telephone: { type: 'mobile', allowEmpty: false },
+        };
+        const jsCode = jsValidator.convert(rule).build();
+        assert(jsCode !== '');
+    });
+
 });