|
1 | | -// Copyright 2015-2016, Google, Inc. |
2 | | -// Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | -// you may not use this file except in compliance with the License. |
4 | | -// You may obtain a copy of the License at |
5 | | -// |
6 | | -// http://www.apache.org/licenses/LICENSE-2.0 |
7 | | -// |
8 | | -// Unless required by applicable law or agreed to in writing, software |
9 | | -// distributed under the License is distributed on an "AS IS" BASIS, |
10 | | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
11 | | -// See the License for the specific language governing permissions and |
12 | | -// limitations under the License. |
| 1 | +/** |
| 2 | + * Copyright 2016, Google, Inc. |
| 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 | + */ |
13 | 15 |
|
14 | 16 | 'use strict'; |
15 | 17 |
|
16 | 18 | const proxyquire = require(`proxyquire`).noPreserveCache(); |
17 | 19 |
|
18 | 20 | describe(`datastore:quickstart`, () => { |
19 | 21 | let datastoreMock, DatastoreMock; |
| 22 | + const error = new Error(`error`); |
| 23 | + const mockKey = {}; |
20 | 24 |
|
21 | 25 | before(() => { |
22 | 26 | datastoreMock = { |
23 | | - get: sinon.stub().yields(null, { key: 1234567890 }), |
24 | | - key: sinon.stub.returns(`task/1234`) |
| 27 | + get: sinon.stub().yields(error), |
| 28 | + key: sinon.stub().returns(mockKey) |
25 | 29 | }; |
26 | 30 | DatastoreMock = sinon.stub().returns(datastoreMock); |
27 | 31 | }); |
28 | 32 |
|
29 | | - it(`should get a task from Datastore`, () => { |
| 33 | + it(`should handle error`, () => { |
30 | 34 | proxyquire(`../quickstart`, { |
31 | 35 | '@google-cloud/datastore': DatastoreMock |
32 | 36 | }); |
33 | 37 |
|
34 | 38 | assert.equal(DatastoreMock.calledOnce, true); |
35 | 39 | assert.deepEqual(DatastoreMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); |
36 | 40 | assert.equal(datastoreMock.get.calledOnce, true); |
37 | | - assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234567890])]); |
| 41 | + assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [mockKey]); |
| 42 | + assert.equal(console.error.calledOnce, true); |
| 43 | + assert.deepEqual(console.error.firstCall.args, [error]); |
38 | 44 | }); |
39 | 45 | }); |
0 commit comments