Advertisement
theRoUS

JS IIFE and looping

Nov 22nd, 2016
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/node
  2. /*
  3.  * Modules we need/use.
  4.  */
  5. var util        = require('util');
  6. var chai        = require('chai');
  7. var expect      = chai.expect;
  8.  
  9. OptionalString      = function(val) {
  10.   result        = (val == void(0)) || (typeof(val) == 'string');
  11.   util.puts('OptionalString(' + util.inspect(val) + ')=' + result.toString());
  12.   return result;
  13. }
  14.  
  15. const TestData      = {
  16.   'test1': {
  17.     'key1-1':       'value1-1',
  18.     'key1-2':       'value2-2',
  19.   },
  20.   'test2': {
  21.     'key2-1':       'value2-1',
  22.     'key2-2':       'value2-2',
  23.   },
  24.   'test3': {
  25.     'key3-1':       null,
  26.     'key3-2':       19,
  27.     'key3-3':       undefined,
  28.   },
  29. }
  30.  
  31. var testElt;
  32. var fieldVal;
  33.  
  34. for (var testKey in TestData) {
  35.   testElt       = TestData[testKey];
  36.   describe('Checking test key ' + testKey, function () {
  37.     for (var fieldName in testElt) {
  38.       fieldVal      = testElt[fieldName];
  39.       describe(testKey + '[' + fieldName + ']', function () {
  40.         it(testKey + '[' + fieldName + '](' + fieldVal + ')', function () {
  41.           expect(fieldVal).to.equal(fieldVal);
  42.           expect(fieldVal).to.satisfy(OptionalString);
  43.         });
  44.       });
  45.     }
  46.   });
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement