Repository: char0n/ramda-adjunct
Pull request #997 (2019-07-21 13:45:14)

isNan/isNotNaN test consistency


Patch:
diff --git a/src/isNaN.js b/src/isNaN.js
index 40a04fc1d9..834187c867 100644
--- a/src/isNaN.js
+++ b/src/isNaN.js
@@ -1,7 +1,10 @@
 import curry1 from 'ramda/src/internal/_curry1';
 
+import isFunction from './isFunction';
 import polyfill from './internal/polyfills/Number.isNaN';
 
+export const isNaNPolyfill = curry1(polyfill);
+
 /**
  * Checks whether the passed value is `NaN` and its type is `Number`.
  * It is a more robust version of the original, global isNaN().
@@ -35,6 +38,6 @@ import polyfill from './internal/polyfills/Number.isNaN';
  * RA.isNaN(''); // => false
  * RA.isNaN(' '); // => false
  */
-const _isNaN = curry1(Number.isNaN || polyfill);
+const _isNaN = isFunction(Number.isNaN) ? curry1(Number.isNaN) : isNaNPolyfill;
 
 export default _isNaN;


Test patch:
diff --git a/test/allEqual.js b/test/allEqual.js
index 82eef1e2cf..ebd4433a1d 100644
--- a/test/allEqual.js
+++ b/test/allEqual.js
@@ -11,7 +11,7 @@ const hasFunctionReferenceEqualityBug = (() => {
 
 describe('allEqual', function() {
   context('given all items are equal', function() {
-    specify('returns true', function() {
+    specify('should return true', function() {
       assert.isTrue(RA.allEqual([4, 4, 4, 4]));
     });
   });
diff --git a/test/isNaN.js b/test/isNaN.js
index a58769553a..4ea7c56cf7 100644
--- a/test/isNaN.js
+++ b/test/isNaN.js
@@ -1,55 +1,61 @@
 import * as R from 'ramda';
+import { assert } from 'chai';
 
 import * as RA from '../src';
-import polyfill from '../src/internal/polyfills/Number.isNaN';
-import eq from './shared/eq';
+import { isNaNPolyfill } from '../src/isNaN';
 
 describe('isNaN', function() {
   it('should test value for a `NaN`', function() {
-    eq(RA.isNaN(NaN), true);
-    eq(RA.isNaN(Number.NaN), true);
-    eq(RA.isNaN(0 / 0), true);
+    assert.isTrue(RA.isNaN(NaN));
+    assert.isTrue(RA.isNaN(Number.NaN));
+    assert.isTrue(RA.isNaN(0 / 0));
 
     // e.g. these would have been true with global isNaN().
-    eq(RA.isNaN('NaN'), false);
-    eq(RA.isNaN(undefined), false);
-    eq(RA.isNaN({}), false);
-    eq(RA.isNaN('blabla'), false);
-
-    // These all return false.
-    eq(RA.isNaN(true), false);
-    eq(RA.isNaN(null), false);
-    eq(RA.isNaN(37), false);
-    eq(RA.isNaN('37'), false);
-    eq(RA.isNaN('37.37'), false);
-    eq(RA.isNaN(''), false);
-    eq(RA.isNaN(' '), false);
-  });
-
-  it('should test polyfill for a `NaN', function() {
-    eq(polyfill(NaN), true);
-    eq(polyfill(Number.NaN), true);
-    eq(polyfill(0 / 0), true);
-
-    // e.g. these would have been true with global isNaN().
-    eq(polyfill('NaN'), false);
-    eq(polyfill(undefined), false);
-    eq(polyfill({}), false);
-    eq(polyfill('blabla'), false);
-
-    // These all return false.
-    eq(polyfill(true), false);
-    eq(polyfill(null), false);
-    eq(polyfill(37), false);
-    eq(polyfill('37'), false);
-    eq(polyfill('37.37'), false);
-    eq(polyfill(''), false);
-    eq(polyfill(' '), false);
+    assert.isFalse(RA.isNaN('NaN'));
+    assert.isFalse(RA.isNaN(undefined));
+    assert.isFalse(RA.isNaN({}));
+    assert.isFalse(RA.isNaN('blabla'));
+
+    assert.isFalse(RA.isNaN(true));
+    assert.isFalse(RA.isNaN(null));
+    assert.isFalse(RA.isNaN(37));
+    assert.isFalse(RA.isNaN('37'));
+    assert.isFalse(RA.isNaN('37.37'));
+    assert.isFalse(RA.isNaN(''));
+    assert.isFalse(RA.isNaN(' '));
   });
 
   it('should support placeholder to specify "gaps"', function() {
     const isNaN = RA.isNaN(R.__);
 
-    eq(isNaN(NaN), true);
+    assert.isTrue(isNaN(NaN));
+  });
+
+  context('isNaNPolyfill', function() {
+    specify('should test polyfill for a `NaN', function() {
+      assert.isTrue(isNaNPolyfill(NaN));
+      assert.isTrue(isNaNPolyfill(Number.NaN));
+      assert.isTrue(isNaNPolyfill(0 / 0));
+
+      // e.g. these would have been true with global isNaN().
+      assert.isFalse(isNaNPolyfill('NaN'));
+      assert.isFalse(isNaNPolyfill(undefined));
+      assert.isFalse(isNaNPolyfill({}));
+      assert.isFalse(isNaNPolyfill('blabla'));
+
+      assert.isFalse(isNaNPolyfill(true));
+      assert.isFalse(isNaNPolyfill(null));
+      assert.isFalse(isNaNPolyfill(37));
+      assert.isFalse(isNaNPolyfill('37'));
+      assert.isFalse(isNaNPolyfill('37.37'));
+      assert.isFalse(isNaNPolyfill(''));
+      assert.isFalse(isNaNPolyfill(' '));
+    });
+
+    specify('should support placeholder to specify "gaps"', function() {
+      const isNaN = isNaNPolyfill(R.__);
+
+      assert.isTrue(isNaN(NaN));
+    });
   });
 });
diff --git a/test/isNotNaN.js b/test/isNotNaN.js
index 5d4c997c8e..0cc971aceb 100644
--- a/test/isNotNaN.js
+++ b/test/isNotNaN.js
@@ -1,47 +1,62 @@
-import { complement } from 'ramda';
+import * as R from 'ramda';
+import { assert } from 'chai';
 
 import * as RA from '../src';
-import polyfill from '../src/internal/polyfills/Number.isNaN';
-import eq from './shared/eq';
+import { isNaNPolyfill } from '../src/isNaN';
 
 describe('isNotNaN', function() {
-  it('tests a value for complement of `NaN`', function() {
-    eq(RA.isNotNaN(NaN), false);
-    eq(RA.isNotNaN(Number.NaN), false);
-    eq(RA.isNotNaN(0 / 0), false);
-
-    eq(RA.isNotNaN('NaN'), true);
-    eq(RA.isNotNaN(undefined), true);
-    eq(RA.isNotNaN({}), true);
-    eq(RA.isNotNaN('blabla'), true);
-
-    eq(RA.isNotNaN(true), true);
-    eq(RA.isNotNaN(null), true);
-    eq(RA.isNotNaN(37), true);
-    eq(RA.isNotNaN('37'), true);
-    eq(RA.isNotNaN('37.37'), true);
-    eq(RA.isNotNaN(''), true);
-    eq(RA.isNotNaN(' '), true);
+  it('should test value for complement of `NaN`', function() {
+    assert.isFalse(RA.isNotNaN(NaN));
+    assert.isFalse(RA.isNotNaN(Number.NaN));
+    assert.isFalse(RA.isNotNaN(0 / 0));
+
+    assert.isTrue(RA.isNotNaN('NaN'));
+    assert.isTrue(RA.isNotNaN(undefined));
+    assert.isTrue(RA.isNotNaN({}));
+    assert.isTrue(RA.isNotNaN('blabla'));
+
+    assert.isTrue(RA.isNotNaN(true));
+    assert.isTrue(RA.isNotNaN(null));
+    assert.isTrue(RA.isNotNaN(37));
+    assert.isTrue(RA.isNotNaN('37'));
+    assert.isTrue(RA.isNotNaN('37.37'));
+    assert.isTrue(RA.isNotNaN(''));
+    assert.isTrue(RA.isNotNaN(' '));
   });
 
-  it('tests polyfill for complement of `NaN', function() {
-    const polyfillC = complement(polyfill);
-
-    eq(polyfillC(NaN), false);
-    eq(polyfillC(Number.NaN), false);
-    eq(polyfillC(0 / 0), false);
-
-    eq(polyfillC('NaN'), true);
-    eq(polyfillC(undefined), true);
-    eq(polyfillC({}), true);
-    eq(polyfillC('blabla'), true);
-
-    eq(polyfillC(true), true);
-    eq(polyfillC(null), true);
-    eq(polyfillC(37), true);
-    eq(polyfillC('37'), true);
-    eq(polyfillC('37.37'), true);
-    eq(polyfillC(''), true);
-    eq(polyfillC(' '), true);
+  specify('should support placeholder to specify "gaps"', function() {
+    const isNotNaN = RA.isNotNaN(R.__);
+
+    assert.isFalse(isNotNaN(NaN));
+  });
+
+  context('isNotNaNPolyfill', function() {
+    const isNotNaNpolyfill = R.complement(isNaNPolyfill);
+
+    specify('should test polyfill for a `NaN', function() {
+      assert.isFalse(isNotNaNpolyfill(NaN));
+      assert.isFalse(isNotNaNpolyfill(Number.NaN));
+      assert.isFalse(isNotNaNpolyfill(0 / 0));
+
+      // e.g. these would have been true with global isNaN().
+      assert.isTrue(isNotNaNpolyfill('NaN'));
+      assert.isTrue(isNotNaNpolyfill(undefined));
+      assert.isTrue(isNotNaNpolyfill({}));
+      assert.isTrue(isNotNaNpolyfill('blabla'));
+
+      assert.isTrue(isNotNaNpolyfill(true));
+      assert.isTrue(isNotNaNpolyfill(null));
+      assert.isTrue(isNotNaNpolyfill(37));
+      assert.isTrue(isNotNaNpolyfill('37'));
+      assert.isTrue(isNotNaNpolyfill('37.37'));
+      assert.isTrue(isNotNaNpolyfill(''));
+      assert.isTrue(isNotNaNpolyfill(' '));
+    });
+
+    specify('should support placeholder to specify "gaps"', function() {
+      const should = isNotNaNpolyfill(R.__);
+
+      assert.isFalse(should(NaN));
+    });
   });
 });
diff --git a/test/sign.js b/test/sign.js
index e91f59f4c4..4026bb9204 100644
--- a/test/sign.js
+++ b/test/sign.js
@@ -93,7 +93,7 @@ describe('sign', function() {
       }
     });
 
-    it('should return proper sign result', function() {
+    specify('should return proper sign result', function() {
       eq(signPolyfill(3), 1);
       eq(signPolyfill(3.3), 1);
       eq(signPolyfill(-3), -1);