Debian Codegraph @

closure-library/closure/goog/labs/testing/assertthat_test.js

raw
1 // Copyright 2012 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.labs.testing.assertThatTest');
16 goog.setTestOnly('goog.labs.testing.assertThatTest');
17
18 goog.require('goog.labs.testing.MatcherError');
19 goog.require('goog.labs.testing.assertThat');
20 goog.require('goog.testing.jsunit');
21 goog.require('goog.testing.recordFunction');
22
23 var successMatchesFn, failureMatchesFn, describeFn, successTestMatcher;
24 var failureTestMatcher;
25
26 function setUp() {
27 successMatchesFn =
28 new goog.testing.recordFunction(function() { return true; });
29 failureMatchesFn =
30 new goog.testing.recordFunction(function() { return false; });
31 describeFn = new goog.testing.recordFunction();
32
33 successTestMatcher = function() {
34 return {matches: successMatchesFn, describe: describeFn};
35 };
36 failureTestMatcher = function() {
37 return {matches: failureMatchesFn, describe: describeFn};
38 };
39 }
40
41 function testAssertthatAlwaysCallsMatches() {
42 var value = 7;
43 goog.labs.testing.assertThat(
44 value, successTestMatcher(), 'matches is called on success');
45
46 assertEquals(1, successMatchesFn.getCallCount());
47 var matchesCall = successMatchesFn.popLastCall();
48 assertEquals(value, matchesCall.getArgument(0));
49
50 var e = assertThrows(
51 goog.bind(
52 goog.labs.testing.assertThat, null, value, failureTestMatcher(),
53 'matches is called on failure'));
54
55 assertTrue(e instanceof goog.labs.testing.MatcherError);
56
57 assertEquals(1, failureMatchesFn.getCallCount());
58 }
59
60 function testAssertthatCallsDescribeOnFailure() {
61 var value = 7;
62 var e = assertThrows(
63 goog.bind(
64 goog.labs.testing.assertThat, null, value, failureTestMatcher(),
65 'describe is called on failure'));
66
67 assertTrue(e instanceof goog.labs.testing.MatcherError);
68
69 assertEquals(1, failureMatchesFn.getCallCount());
70 assertEquals(1, describeFn.getCallCount());
71
72 var matchesCall = describeFn.popLastCall();
73 assertEquals(value, matchesCall.getArgument(0));
74 }