mock-gcs is a TypeScript library providing mock implementations of Google Cloud Storage SDK classes (Storage, Bucket, File) for testing and development. Version 2.1.0 supports most basic features like bucket and file operations, upload/download, signed URLs, and error simulation via mockErrorOnce. It also exports TypeScript interfaces (IStorage, IBucket, IFile) to facilitate type-safe code that works with both @google-cloud/storage and mock-gcs. The library is actively maintained and encourages community contributions for missing methods.
npm install mock-gcsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates how to use MockStorage in a class that accepts IStorage for type safety, then test with mock.
Use import syntax or const { MockStorage } = await import('mock-gcs');Check available methods in documentation; submit PR for missing ones.
Use async/await or Promise.then().
Call mockErrorOnce before the method you want to fail.
npm install mock-gcs
Use: const storage = new MockStorage(); // not MockStorage() without new
Use IFile type or cast to any: (file as any).mockErrorOnce('method', error)