aboutsummaryrefslogtreecommitdiff
path: root/test/options.test.ts
blob: 8622c73a2c09531986df39e9983c9ca8de423e6a (plain) (blame)
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
import * as mocha from 'mocha';
import chai = require('chai');
var should = chai.should();

import * as options from '../src/matcher/options';
import { default as types } from '../src/matcher/types';

describe('Object Matching:', () => {
  describe('Rough Matching', () => {
    it('accepts basic things', () => {
      let template = {
        a: types.string
      };
      let matchee = {
        a: "yes"
      };
      options.rough(template, matchee).should.be.true;
    });
    it('accepts objects with superfluous properties', () => {
      let template = {
        a: types.number
      };
      let matchee = {
        a: 40,
        b: 20
      };
      options.rough(template, matchee).should.be.true;
    });
    it('rejects objects missing some properties', () => {
      let template = {
        a: types.boolean,
        b: types.number,
        c: types.number
      };
      let matchee = {
        b: 5
      };
      options.rough(template, matchee).should.be.false;
    });
    it('accepts objects that omit not_present properties', () => {
      let template = {
        a: types.function,
        b: types.not_present,
        c: types.not_present
      };
      let matchee = {
        a: new Function()
      };
      options.rough(template, matchee).should.be.true;
    });
  });
});