Debian Codegraph @

closure-library/closure/goog/debug/errorcontext_test.js

raw
1 // Copyright 2017 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.module('goog.debug.errorcontextTest');
16 goog.setTestOnly('goog.debug.errorcontextTest');
17
18 const errorcontext = goog.require('goog.debug.errorcontext');
19 const testSuite = goog.require('goog.testing.testSuite');
20 goog.require('goog.testing.jsunit');
21
22 testSuite({
23 testAddContext() {
24 const err = new Error('something happened');
25 assertObjectEquals({}, errorcontext.getErrorContext(err));
26
27 errorcontext.addErrorContext(err, 'key', 'value');
28 assertObjectEquals({key: 'value'}, errorcontext.getErrorContext(err));
29
30 errorcontext.addErrorContext(err, 'another_key', 'another_value');
31 assertObjectEquals(
32 {key: 'value', another_key: 'another_value'},
33 errorcontext.getErrorContext(err));
34
35 // Overwrite the first context value.
36 errorcontext.addErrorContext(err, 'key', 'new_value');
37 assertObjectEquals(
38 {key: 'new_value', another_key: 'another_value'},
39 errorcontext.getErrorContext(err));
40 },
41 });