|
| 1 | +/** |
| 2 | + * Copyright 2019 Google LLC. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import {assert} from 'chai'; |
| 18 | +import * as sinon from 'sinon'; |
| 19 | + |
| 20 | +import {warn} from '../src/warnings'; |
| 21 | + |
| 22 | +describe('warnings', () => { |
| 23 | + it('should warn the given code once with the first message', (done) => { |
| 24 | + const stub = sinon.stub(process, 'emitWarning'); |
| 25 | + warn('code1', 'message1-1'); |
| 26 | + warn('code1', 'message1-2'); |
| 27 | + warn('code1', 'message1-3'); |
| 28 | + assert(stub.calledOnceWith('message1-1')); |
| 29 | + stub.restore(); |
| 30 | + done(); |
| 31 | + }); |
| 32 | + it('should warn each code once', (done) => { |
| 33 | + const stub = sinon.stub(process, 'emitWarning'); |
| 34 | + warn('codeA', 'messageA-1'); |
| 35 | + warn('codeB', 'messageB-1'); |
| 36 | + warn('codeA', 'messageA-2'); |
| 37 | + warn('codeB', 'messageB-2'); |
| 38 | + warn('codeC', 'messageC-1'); |
| 39 | + warn('codeA', 'messageA-3'); |
| 40 | + assert.strictEqual(stub.callCount, 3); |
| 41 | + stub.restore(); |
| 42 | + done(); |
| 43 | + }); |
| 44 | +}); |
0 commit comments