aboutsummaryrefslogtreecommitdiffstats
path: root/test/scenario/MatcherSpec.js
blob: 2eddd2bcf1e70705f92e63f52c50a3a77735e588 (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
describe('Matcher', function () {
  function executeFutures() {
    for(var i in $scenario.currentSpec.futures) {
      var future = $scenario.currentSpec.futures[i];
      future.behavior.call({}, function(value) { future.fulfill(value); });
    }
  }
  var matcher;
  beforeEach(function() {
    setUpContext();
    var future = $scenario.addFuture('Calculate first future', function(done) {
      done(123);
    });
    matcher = new Matcher(this, future);

  });
  it('should correctly match toEqual', function() {
    matcher.toEqual(123);
    executeFutures();
  });
  it('should throw an error when incorrect match toEqual', function() {
    matcher.toEqual(456);
    try {
      executeFutures();
      fail();
    } catch (e) {
      expect(e).toEqual('Expected 456 but was 123');
    }
  });
  it('should correctly match arrays', function() {
    var future = $scenario.addFuture('Calculate first future', function(done) {
      done(['a', 'b']);
    });
    matcher = new Matcher(this, future);
    matcher.toEqual(['a', 'b']);
    executeFutures();
  });
});