Skip to content

Commit bc40a99

Browse files
authored
test: Remove mock so that future tests will not be affected by the mock (#1099)
* Ensure the mock isn’t permanent for other cases Reassign this mock back to what it was because future tests will rely on this being the proper value. * Add async to verify the change works Async will run all the tests twice failing if the prior change was not implemented. * Revert "Add async to verify the change works" This reverts commit 57855a3. * Adjust the comment slightly Adjust the comment slightly to address the fact that we are changing the mocked function back to the way it was. * Refactor the mock out into a constant The mock should be a constant instead of repeating a code fragment that must be the same. * Surround with try/finally We can use try/finally so that even if the test fails the mock gets reset. * Revert "Surround with try/finally" This reverts commit 73bea28. * Have a fake entity init state Have a fake entity init state and then before each test initialize the fakeEntity from the fakeEntityInit state. * Remove resetting the mock in individual tests Now that we initialize the fake entity at the beginning of every single test, we do not need to reset the mock in that one test anymore. * Eliminate unused variable Variable is not used anymore so should be eliminated from the code change.
1 parent af9ed6d commit bc40a99

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import * as extend from 'extend';
3030
const v1 = require('../src/v1/index.js');
3131

3232
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33-
const fakeEntity: any = {
33+
const fakeEntityInit: any = {
3434
KEY_SYMBOL: Symbol('fake key symbol'),
3535
Int: class {
3636
value: {};
@@ -82,6 +82,8 @@ const fakeEntity: any = {
8282
URLSafeKey: entity.URLSafeKey,
8383
};
8484

85+
const fakeEntity: any = {};
86+
8587
let googleAuthOverride: Function | null;
8688
function fakeGoogleAuth(...args: Array<{}>) {
8789
return (googleAuthOverride || (() => {}))(...args);
@@ -157,6 +159,7 @@ describe('Datastore', () => {
157159
};
158160

159161
before(() => {
162+
Object.assign(fakeEntity, fakeEntityInit);
160163
Datastore = proxyquire('../src', {
161164
'./entity.js': {entity: fakeEntity},
162165
'./index-class.js': {Index: FakeIndex},
@@ -171,6 +174,8 @@ describe('Datastore', () => {
171174
});
172175

173176
beforeEach(() => {
177+
Object.assign(fakeEntity, fakeEntityInit);
178+
174179
createInsecureOverride = null;
175180
googleAuthOverride = null;
176181

0 commit comments

Comments
 (0)