Repository: skovhus/jest-codemods
Pull request #121 (2018-07-17 21:26:33)

adds expect/should aliases gt, lt, greaterThan
- Addresses https://github.com/skovhus/jest-codemods/issues/120
- Added tests for new aliases.


Patch:
diff --git a/src/transformers/chai-should.js b/src/transformers/chai-should.js
index 47394ce..909c7da 100644
--- a/src/transformers/chai-should.js
+++ b/src/transformers/chai-should.js
@@ -23,9 +23,12 @@ const fns = [
     'contain',
     'eql',
     'above',
+    'gt',
+    'greaterthan',
     'least',
     'below',
     'lessthan',
+    'lt',
     'most',
     'match',
     'string',
@@ -389,6 +392,8 @@ module.exports = function transformer(fileInfo, api, options) {
                     case 'eql':
                         return createCall('toEqual', args, rest, containsNot);
                     case 'above':
+                    case 'greaterthan':
+                    case 'gt':
                         return createCall('toBeGreaterThan', args, rest, containsNot);
                     case 'least':
                     case 'gte':
@@ -400,6 +405,7 @@ module.exports = function transformer(fileInfo, api, options) {
                         );
                     case 'below':
                     case 'lessthan':
+                    case 'lt':
                         return createCall('toBeLessThan', args, rest, containsNot);
                     case 'most':
                     case 'lte':
diff --git a/src/transformers/expect-js.js b/src/transformers/expect-js.js
index 0d78a2d..523a2e2 100644
--- a/src/transformers/expect-js.js
+++ b/src/transformers/expect-js.js
@@ -21,8 +21,10 @@ const MATCHES = {
     key: 'toHaveProperty',
     above: 'toBeGreaterThan',
     greaterThan: 'toBeGreaterThan',
+    gt: 'toBeGreaterThan',
     below: 'toBeLessThan',
     lessThan: 'toBeLessThan',
+    lt: 'toBeLessThan',
     match: 'toMatch',
 };
 


Test patch:
diff --git a/src/transformers/chai-should.test.js b/src/transformers/chai-should.test.js
index 9e4d092..54a8349 100644
--- a/src/transformers/chai-should.test.js
+++ b/src/transformers/chai-should.test.js
@@ -109,8 +109,16 @@ testChanged(
 
 testChanged(
     'converts "above"',
-    `expect(10).to.be.above(5);`,
-    `expect(10).toBeGreaterThan(5);`
+    `
+        expect(10).to.be.above(5);
+        expect(10).to.be.gt(5);
+        expect(10).to.be.greaterThan(5);
+    `,
+    `
+        expect(10).toBeGreaterThan(5);
+        expect(10).toBeGreaterThan(5);
+        expect(10).toBeGreaterThan(5);
+    `
 );
 
 testChanged(
@@ -120,13 +128,17 @@ testChanged(
         expect(5).to.be.below(10, 'error message');
         expect(3).to.be.at.below(5);
         expect(2).to.be.lessThan(5);
+        expect(2).to.be.lt(5);
         (1).should.be.lessThan(5);
+        (1).should.be.lt(5);
     `,
     `
         expect(5).toBeLessThan(10);
         expect(5).toBeLessThan(10);
         expect(3).toBeLessThan(5);
         expect(2).toBeLessThan(5);
+        expect(2).toBeLessThan(5);
+        expect(1).toBeLessThan(5);
         expect(1).toBeLessThan(5);
     `
 );
diff --git a/src/transformers/expect-js.test.js b/src/transformers/expect-js.test.js
index 9e3f0d0..69e074e 100644
--- a/src/transformers/expect-js.test.js
+++ b/src/transformers/expect-js.test.js
@@ -151,14 +151,18 @@ testChanged(
     test(() => {
       expect(stuff).to.be.lessThan(42);
       expect(stuff).to.be.below(42);
+      expect(stuff).to.be.lt(42);
       expect(stuff).to.be.greaterThan(42);
       expect(stuff).to.be.above(42);
+      expect(stuff).to.be.gt(42);
     });
     `,
     `
     test(() => {
       expect(stuff).toBeLessThan(42);
       expect(stuff).toBeLessThan(42);
+      expect(stuff).toBeLessThan(42);
+      expect(stuff).toBeGreaterThan(42);
       expect(stuff).toBeGreaterThan(42);
       expect(stuff).toBeGreaterThan(42);
     });