Welcome to mirror list, hosted at ThFree Co, Russian Federation.

grep.spec.js « test « mocha-3.1.0 « lib « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bbc5c55ebadabd662320dc2f6a0cec4661abfc65 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var Mocha = require('../');

describe('Mocha', function(){
  describe('"grep" option', function(){
    it('should add a RegExp to the mocha.options object', function(){
      var mocha = new Mocha({ grep: /foo.*/ });
      mocha.options.grep.toString().should.equal('/foo.*/');
    });

    it('should convert string to a RegExp', function(){
      var mocha = new Mocha({ grep: 'foo.*' });
      mocha.options.grep.toString().should.equal('/foo.*/');
    });
  });

  describe('"fgrep" option', function(){
    it('should escape and convert string to a RegExp', function(){
      var mocha = new Mocha({ fgrep: 'foo.*' });
      mocha.options.grep.toString().should.equal('/foo\\.\\*/');
    });
  });

  describe('.grep()', function() {
    // Test helper
    function testGrep(mocha) {
      return function testGrep(grep, expected) {
        mocha.grep(grep);
        mocha.options.grep.toString().should.equal(expected);
      }
    }

    it('should add a RegExp to the mocha.options object', function() {
      var test = testGrep(new Mocha);
      test(/foo/, '/foo/');
    });

    it('should convert grep string to a RegExp', function() {
      var test = testGrep(new Mocha);
      test('foo', '/foo/');
      test('^foo.*bar$', '/^foo.*bar$/');
      test('^@.*(?=\\(\\)$)', '/^@.*(?=\\(\\)$)/');
    });

    it('should covert grep regex-like string to a RegExp', function() {
      var test = testGrep(new Mocha);
      test('/foo/', '/foo/');
      // Keep the flags
      test('/baz/i', '/baz/i');
      test('/bar/g', '/bar/g');
      test('/^foo(.*)bar/g', '/^foo(.*)bar/g');
    });

    it('should return it\'s parent Mocha object for chainability', function(){
      var mocha = new Mocha;
      mocha.grep().should.equal(mocha);
    });
  });

  describe('"invert" option', function(){
    it('should add a Boolean to the mocha.options object', function(){
      var mocha = new Mocha({ invert: true });
      mocha.options.invert.should.be.ok;
    });
  });
});