How to use node-tdd - 10 common examples

To help you get started, we’ve selected a few node-tdd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blackflux / object-scan / test / index.spec.js View on Github external
expect(result).to.deep.equal(['one.child']);
      });

      it('Testing array parents useArraySelector == false', () => {
        const result = objectScan(pattern, {
          filterFn: (k, v, { parents }) => {
            expect(parents).to.deep.equal([input.one.child, input.one, input]);
          },
          useArraySelector: false
        })(input);
        expect(result).to.deep.equal(['one.child[2]', 'one.child[1]', 'one.child[0]']);
      });
    });
  });

  describe('Testing useArraySelector + breakFn', () => {
    const input = { child: [{ id: 1 }] };
    const pattern = ['child.id', 'child[0].id'];

    const execTest = (useArraySelector, breakFn) => {
      const result = [];
      objectScan(pattern, {
        breakFn: (k) => {
          result.push(k);
          return breakFn(k);
        },
        useArraySelector
      })(input);
      return result;
    };

    it('Testing useArraySelector = false, breakFn (BREAKING)', () => {
github blackflux / object-scan / test / util / parser.spec.js View on Github external
describe('Testing Parser', () => {
  describe('Complex Use Cases', () => {
    it('Testing Path Groups', () => {
      expect(asString('{a,b.c}')).to.equal('{"a",["b","c"]}');
    });

    it('Testing Nested Groups', () => {
      expect(asString('{a,{b,c}}')).to.deep.equal('{"a","b","c"}');
      expect(asString('{a,{b,{c}}}')).to.deep.equal('{"a","b","c"}');
    });

    it('Testing Array Group Content', () => {
      expect(asString('[{1,{0,1}}]')).to.deep.equal('{"[1]","[0]","[1]"}');
      expect(asString('[{{0,1},1}]')).to.deep.equal('{"[0]","[1]","[1]"}');
    });
  });

  describe('Testing Simple Use Cases', () => {
github blackflux / object-scan / test / util / parser.spec.js View on Github external
it('Testing Exclusion in Path Group', () => {
      expect(asString('**.{*,!location}.lat'))
        .to.equal('["**",{"*",!"location"},"lat"]');
    });

    it('Testing Redundant Exclusion', () => {
      expect(asString('!a.!b')).to.equal('[!"a",!"b"]');
    });

    it('Nested Redundant Exclusions', () => {
      expect(asString('!{[1][2],*,{a,b},{a},{{a}},{a.!b}}'))
        .to.equal('{[!"[1]","[2]"],!"*",!"a",!"b",!"a",!"a",[!"a",!"b"]}');
    });

    describe('Testing Exclusion Errors', () => {
      it('Testing double exclusion', () => {
        checkError('!!text', 'Bad Exclusion: !!text, char 1');
      });

      it('Testing redundant exclusion', () => {
        checkError('!{!a,b}', 'Redundant Exclusion: !{!a,b}, char 2');
      });

      it('Testing redundant exclusion (deeply nested)', () => {
        checkError('!{a,{{!b}}}', '!{a,{{!b}}}, char 6');
      });

      it('Testing in-word exclusion', () => {
        checkError('test.te!st', 'Bad Exclusion: test.te!st, char 7');
      });
github blackflux / object-scan / test / util / parser.spec.js View on Github external
if (Array.isArray(input)) {
      return `[${input.map((e) => asStringRec(e)).join(',')}]`;
    }
    if (input instanceof Set) {
      return `{${[...input].map((e) => asStringRec(e)).join(',')}}`;
    }
    return `${input.isExcluded() ? '!' : ''}"${input}"`;
  };
  return (input) => asStringRec(parser(input));
})();

const checkError = (input, msg) => {
  expect(() => parser(input)).to.throw(msg);
};

describe('Testing Parser', () => {
  describe('Complex Use Cases', () => {
    it('Testing Path Groups', () => {
      expect(asString('{a,b.c}')).to.equal('{"a",["b","c"]}');
    });

    it('Testing Nested Groups', () => {
      expect(asString('{a,{b,c}}')).to.deep.equal('{"a","b","c"}');
      expect(asString('{a,{b,{c}}}')).to.deep.equal('{"a","b","c"}');
    });

    it('Testing Array Group Content', () => {
      expect(asString('[{1,{0,1}}]')).to.deep.equal('{"[1]","[0]","[1]"}');
      expect(asString('[{{0,1},1}]')).to.deep.equal('{"[0]","[1]","[1]"}');
    });
  });
github blackflux / object-scan / test / index.spec.js View on Github external
});

      it('Inclusion after exclusion', () => {
        execute(fixture, ['!*.x', 'a.x'], ['a.x']);
      });

      it('Inclusion only', () => {
        execute(fixture, ['*.x'], ['e.x', 'd.x', 'c.x', 'b.x', 'a.x']);
      });

      it('Exclusions only', () => {
        execute(fixture, ['!a.x', '!b.x'], []);
      });
    });

    describe('Testing Misc Exclusions', () => {
      const fixture1 = { foo: '', bar: '', baz: '' };
      const fixture2 = {
        foo: '', foam: '', for: '', forum: ''
      };
      const fixture3 = {
        foo: '', one: '', two: '', four: '', do: '', once: '', only: ''
      };

      it('Basic exclusion', () => {
        execute(fixture1, ['foo'], ['foo']);
        execute(fixture1, ['!foo'], []);
        execute(fixture1, ['foo', 'bar'], ['bar', 'foo']);
      });

      it('Exclusion only, no results', () => {
        execute(fixture1, ['!foo', '!bar'], []);
github blackflux / lambda-monitor / test / logic / util / cfn-response-wrapper.spec.js View on Github external
expect(args).to.equal('args');
    callback(errObject, respObject);
  })(sampleEvent, {}, (e, r) => resolve([e, r]), 'args'));
  expect(err).to.equal(errObject);
  expect(resp).to.equal(respObject);
  expect(recorder.get()).to.deep.equal([
    'Response body:\n',
    `{"Status":"${status.toUpperCase()}","Reason":"See the details in CloudWatch Log Stream: undefined",`
    + '"StackId":"arn:aws:cloudformation:eu-west-1:...","RequestId":"afd8d7c5-9376-4013-8b3b-307517b8719e",'
    + '"LogicalResourceId":"Route53","Data":{}}',
    'Status code: 200',
    'Status message: null'
  ]);
};

describe('Testing cfn-response-wrapper', { record: console, useNock: true }, () => {
  it('Testing Callback Execution Success', async ({ recorder }) => {
    await doTest(null, 'response', 'SUCCESS', recorder);
  });

  it('Testing Callback Execution Failure', async ({ recorder }) => {
    await doTest('err', undefined, 'FAILED', recorder);
  });
});
github blackflux / object-scan / test / index.spec.js View on Github external
})({
        tag: [[{ id: 1 }]]
      });
      expect(result).to.deep.equal([
        ['breakFn', ''],
        ['breakFn', 'tag'],
        ['breakFn', 'tag[0]'],
        ['breakFn', 'tag[0][0]'],
        ['breakFn', 'tag[0][0].id'],
        ['filterFn', 'tag[0][0].id'],
        ['filterFn', 'tag[0][0]']
      ]);
    });
  });

  describe('Testing Fn traversedBy', () => {
    const input = [{ parent: { child: 'value' } }];
    const pattern = ['[*].*.child', '[*].parent'];

    it('Testing traversedBy on filterFn', () => {
      const result = [];
      objectScan(pattern, { filterFn: (k, v, { traversedBy }) => result.push(`${traversedBy} => ${k}`) })(input);
      expect(result).to.deep.equal([
        '[*].*.child => [0].parent.child',
        '[*].*.child,[*].parent => [0].parent'
      ]);
    });

    it('Testing traversedBy on breakFn', () => {
      const result = [];
      objectScan(pattern, {
        breakFn: (k, v, { isMatch, traversedBy }) => result.push(`${traversedBy} => ${k} (${isMatch})`)
github blackflux / object-scan / test / index.spec.js View on Github external
'array3[0].item'
    ]);
  });

  it('Testing Filter Function', () => {
    const find = objectScan(['**'], {
      filterFn: (key, value) => typeof value === 'string' && value === 'a'
    });
    expect(find(haystack)).to.deep.equal([
      'array2.nested[0]',
      'array1[0]',
      'simple'
    ]);
  });

  describe('Testing Escaping', () => {
    it('Testing Escaped Char Matching', () => {
      ['?', '!', ',', '.', '*', '[', ']', '{', '}'].forEach((char) => {
        const find = objectScan([`\\${char}`]);
        expect(find({ [char]: 'a', b: 'c' })).to.deep.equal([`\\${char}`]);
      });
    });

    it('Testing Escaped Star', () => {
      const find = objectScan(['a.\\[\\*\\]']);
      expect(find({ a: { '[*]': 'b', '[x]': 'c' } })).to.deep.equal([
        'a.\\[\\*\\]'
      ]);
    });

    it('Testing Escaped Comma', () => {
      const find = objectScan(['{a\\,b,c\\,d,f\\\\\\,g}']);
github blackflux / object-scan / test / index.spec.js View on Github external
});

  it('Testing Array Wildcard', () => {
    const find = objectScan(['**[1*]']);
    expect(find(haystack)).to.deep.equal([
      'array4[12]',
      'array4[11]',
      'array4[10]',
      'array4[1]',
      'array3[1]',
      'array2.nested[1]',
      'array1[1]'
    ]);
  });

  describe('Testing wildcard matching', () => {
    const fixture = {
      foo: { bar: '', mark: '' },
      sub: { baz: '', dow: '' },
      gaw: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
    };

    it('Testing Star Wildcard', () => {
      expect(objectScan(['f*oo'])(fixture)).to.deep.equal(['foo']);
      expect(objectScan(['f*o'])(fixture)).to.deep.equal(['foo']);
      expect(objectScan(['gaw[*2]'])(fixture)).to.deep.equal(['gaw[22]', 'gaw[12]', 'gaw[2]']);
      expect(objectScan(['gaw[*22]'])(fixture)).to.deep.equal(['gaw[22]']);
    });

    it('Testing Questionmark Wildcard', () => {
      expect(objectScan(['f?oo'])(fixture)).to.deep.equal([]);
      expect(objectScan(['f?o'])(fixture)).to.deep.equal(['foo']);
github blackflux / object-scan / test / index.spec.js View on Github external
it('Testing Star Wildcard', () => {
      expect(objectScan(['f*oo'])(fixture)).to.deep.equal(['foo']);
      expect(objectScan(['f*o'])(fixture)).to.deep.equal(['foo']);
      expect(objectScan(['gaw[*2]'])(fixture)).to.deep.equal(['gaw[22]', 'gaw[12]', 'gaw[2]']);
      expect(objectScan(['gaw[*22]'])(fixture)).to.deep.equal(['gaw[22]']);
    });

    it('Testing Questionmark Wildcard', () => {
      expect(objectScan(['f?oo'])(fixture)).to.deep.equal([]);
      expect(objectScan(['f?o'])(fixture)).to.deep.equal(['foo']);
      expect(objectScan(['gaw[?2]'])(fixture)).to.deep.equal(['gaw[22]', 'gaw[12]']);
      expect(objectScan(['gaw[?22]'])(fixture)).to.deep.equal([]);
    });
  });

  describe('Testing greedy array matching', () => {
    const needles = ['*'];
    const input = { key: ['v1', 'v2'] };
    it('Testing arrays not matched with useArraySelector === true', () => {
      const find = objectScan(needles, { useArraySelector: true });
      expect(find(input)).to.deep.equal(['key']);
    });

    it('Testing arrays matched with useArraySelector === false', () => {
      const find = objectScan(needles, { useArraySelector: false });
      expect(find(input)).to.deep.equal(['key[1]', 'key[0]']);
    });
  });

  describe('Testing Exclusion', () => {
    const execute = (input, needles, result) => expect(objectScan(needles)(input)).to.deep.equal(result);

node-tdd

Drop in extension for mocha to abstract commonly used test setups

MIT
Latest version published 11 days ago

Package Health Score

61 / 100
Full package analysis

Popular node-tdd functions