Jelajahi Sumber

use describe.each and test.each

Yuki Takei 6 tahun lalu
induk
melakukan
d9ec1f517b
3 mengubah file dengan 16 tambahan dan 21 penghapusan
  1. 0 1
      package.json
  2. 4 7
      src/test/middleware/login-required.test.js
  3. 12 13
      src/test/service/acl.test.js

+ 0 - 1
package.json

@@ -181,7 +181,6 @@
     "i18next-browser-languagedetector": "^4.0.1",
     "imports-loader": "^0.8.0",
     "jest": "^24.8.0",
-    "jest-each": "^24.8.0",
     "jquery-slimscroll": "^1.3.8",
     "jquery-ui": "^1.12.1",
     "jquery.cookie": "~1.4.1",

+ 4 - 7
src/test/middleware/login-required.test.js

@@ -1,7 +1,5 @@
 /* eslint-disable arrow-body-style */
 
-import each from 'jest-each';
-
 const { getInstance } = require('../setup-crowi');
 
 describe('loginRequired', () => {
@@ -129,15 +127,13 @@ describe('loginRequired', () => {
       expect(req.session.jumpTo).toBe(undefined);
     });
 
-    each`
+    /* eslint-disable indent */
+    test.each`
       userStatus  | expectedPath
       ${1}        | ${'/login/error/registered'}
       ${3}        | ${'/login/error/suspended'}
       ${5}        | ${'/login/invited'}
-    `
-      .test('redirect to \'$expectedPath\''
-        + ' when user.status is \'$userStatus\' ', ({ userStatus, expectedPath }) => {
-
+    `('redirect to \'$expectedPath\' when user.status is \'$userStatus\'', ({ userStatus, expectedPath }) => {
         req.user = {
           _id: 'user id',
           status: userStatus,
@@ -153,6 +149,7 @@ describe('loginRequired', () => {
         expect(result).toBe('redirect');
         expect(req.session.jumpTo).toBe(undefined);
       });
+    /* eslint-disable indent */
 
     test('redirect to \'/login\' when user.status is \'STATUS_DELETED\'', () => {
       const User = crowi.model('User');

+ 12 - 13
src/test/service/acl.test.js

@@ -1,5 +1,3 @@
-import each from 'jest-each';
-
 const { getInstance } = require('../setup-crowi');
 
 describe('AclService test', () => {
@@ -165,17 +163,17 @@ describe('AclService test', () => {
       expect(result).toBe(true);
     });
 
-    each`
-    restrictGuestMode   | expected
-      ${undefined}      | ${false}
-      ${'Deny'}         | ${false}
-      ${'Readonly'}     | ${true}
-      ${'Open'}         | ${false}
-      ${'Restricted'}   | ${false}
-      ${'closed'}       | ${false}
-    `
-      .test('to be $expected when FORCE_WIKI_MODE is undefined'
-          + ' and `security:restrictGuestMode` is \'$restrictGuestMode\'', async({ restrictGuestMode, expected }) => {
+    /* eslint-disable indent */
+    describe.each`
+      restrictGuestMode   | expected
+      ${undefined}        | ${false}
+      ${'Deny'}           | ${false}
+      ${'Readonly'}       | ${true}
+      ${'Open'}           | ${false}
+      ${'Restricted'}     | ${false}
+      ${'closed'}         | ${false}
+    `('to be $expected', ({ restrictGuestMode, expected }) => {
+      test(`when FORCE_WIKI_MODE is undefined and 'security:restrictGuestMode' is '${restrictGuestMode}`, async() => {
 
         // reload
         await crowi.configManager.loadConfigs();
@@ -198,6 +196,7 @@ describe('AclService test', () => {
         expect(getConfigSpy).toHaveBeenCalledWith('crowi', 'security:restrictGuestMode');
         expect(result).toBe(expected);
       });
+    });
 
   });