Debian Codegraph @

closure-library/closure/goog/labs/testing/dictionarymatcher_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.dictionaryMatcherTest');
16 goog.setTestOnly('goog.labs.testing.dictionaryMatcherTest');
17
18 /** @suppress {extraRequire} */
19 goog.require('goog.labs.testing.HasEntryMatcher');
20 goog.require('goog.labs.testing.MatcherError');
21 goog.require('goog.labs.testing.assertThat');
22 goog.require('goog.testing.jsunit');
23
24 function testHasEntries() {
25 var obj1 = {x: 1, y: 2, z: 3};
26 goog.labs.testing.assertThat(
27 obj1, hasEntries({x: 1, y: 2}), 'obj1 has entries: {x:1, y:2}');
28
29 assertMatcherError(function() {
30 goog.labs.testing.assertThat(obj1, hasEntries({z: 5, a: 4}));
31 }, 'hasEntries should throw exception when it fails');
32 }
33
34 function testHasEntry() {
35 var obj1 = {x: 1, y: 2, z: 3};
36 goog.labs.testing.assertThat(obj1, hasEntry('x', 1), 'obj1 has entry: {x:1}');
37
38 assertMatcherError(function() {
39 goog.labs.testing.assertThat(obj1, hasEntry('z', 5));
40 }, 'hasEntry should throw exception when it fails');
41 }
42
43 function testHasKey() {
44 var obj1 = {x: 1};
45 goog.labs.testing.assertThat(obj1, hasKey('x'), 'obj1 has key x');
46
47 assertMatcherError(function() {
48 goog.labs.testing.assertThat(obj1, hasKey('z'));
49 }, 'hasKey should throw exception when it fails');
50 }
51
52 function testHasValue() {
53 var obj1 = {x: 1};
54 goog.labs.testing.assertThat(obj1, hasValue(1), 'obj1 has value 1');
55
56 assertMatcherError(function() {
57 goog.labs.testing.assertThat(obj1, hasValue(2));
58 }, 'hasValue should throw exception when it fails');
59 }
60
61 function assertMatcherError(callable, errorString) {
62 var e = assertThrows(errorString || 'callable throws exception', callable);
63 assertTrue(e instanceof goog.labs.testing.MatcherError);
64 }