Skip to content

Commit 2fcda8e

Browse files
committed
better test fix
1 parent f7fb6b9 commit 2fcda8e

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

packages/compass-app-stores/src/provider.spec.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ describe('NamespaceProvider', function () {
3434
it('should immediately render content if database exists', async function () {
3535
const instanceManager = new TestMongoDBInstanceManager({
3636
databases: [{ _id: 'foo' }] as any,
37-
preferences,
3837
});
3938
await renderWithActiveConnection(
4039
<PreferencesProvider value={preferences}>
@@ -49,7 +48,6 @@ describe('NamespaceProvider', function () {
4948
it('should immediately render content if collection exists', async function () {
5049
const instanceManager = new TestMongoDBInstanceManager({
5150
databases: [{ _id: 'foo', collections: [{ _id: 'foo.bar' }] }] as any,
52-
preferences,
5351
});
5452
await renderWithActiveConnection(
5553
<PreferencesProvider value={preferences}>
@@ -62,7 +60,7 @@ describe('NamespaceProvider', function () {
6260
});
6361

6462
it("should not render content when namespace doesn't exist", async function () {
65-
const instanceManager = new TestMongoDBInstanceManager({ preferences });
63+
const instanceManager = new TestMongoDBInstanceManager();
6664
await renderWithActiveConnection(
6765
<PreferencesProvider value={preferences}>
6866
<MongoDBInstancesManagerProvider value={instanceManager}>
@@ -74,7 +72,7 @@ describe('NamespaceProvider', function () {
7472
});
7573

7674
it('should render content eventually if namespace is resolved async', async function () {
77-
const instanceManager = new TestMongoDBInstanceManager({ preferences });
75+
const instanceManager = new TestMongoDBInstanceManager();
7876
const instance = instanceManager.getMongoDBInstanceForConnection();
7977
sandbox.stub(instance, 'fetchDatabases').callsFake(() => {
8078
instance.databases.add({ _id: 'foo' });
@@ -100,7 +98,6 @@ describe('NamespaceProvider', function () {
10098
const onNamespaceFallbackSelect = sandbox.spy();
10199
const instanceManager = new TestMongoDBInstanceManager({
102100
databases: [{ _id: 'foo' }] as any,
103-
preferences,
104101
});
105102
await renderWithActiveConnection(
106103
<PreferencesProvider value={preferences}>
@@ -121,9 +118,7 @@ describe('NamespaceProvider', function () {
121118

122119
it('should call onNamespaceFallbackSelect with `null` if namespace is not found', async function () {
123120
const onNamespaceFallbackSelect = sandbox.spy();
124-
const instanceManager = new TestMongoDBInstanceManager({
125-
preferences,
126-
});
121+
const instanceManager = new TestMongoDBInstanceManager();
127122
await renderWithActiveConnection(
128123
<PreferencesProvider value={preferences}>
129124
<MongoDBInstancesManagerProvider value={instanceManager}>

packages/compass-app-stores/src/provider.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ export class TestMongoDBInstanceManager extends MongoDBInstancesManager {
4040
private _instance: MongoDBInstance;
4141
constructor(instanceProps = {} as Partial<MongoDBInstanceProps>) {
4242
super();
43+
if (!instanceProps.preferences) {
44+
instanceProps.preferences = {
45+
getPreferences: () => ({} as AllPreferences),
46+
setPreferences: () => Promise.resolve(),
47+
onPreferenceValueChanged: () => () => {
48+
/* no-op */
49+
},
50+
} as unknown as PreferencesAccess;
51+
}
4352
this._instance = new MongoDBInstance(instanceProps as MongoDBInstanceProps);
4453
}
4554
getMongoDBInstanceForConnection() {
@@ -55,15 +64,7 @@ export class TestMongoDBInstanceManager extends MongoDBInstancesManager {
5564
export const MongoDBInstancesManagerContext =
5665
createContext<MongoDBInstancesManager | null>(
5766
process.env.NODE_ENV === 'test'
58-
? (new TestMongoDBInstanceManager({
59-
preferences: {
60-
getPreferences: () =>
61-
({ enableDbAndCollStats: true } as AllPreferences),
62-
onPreferenceValueChanged: () => () => {
63-
/* noop unsubscribe */
64-
},
65-
} as unknown as PreferencesAccess,
66-
}) as unknown as MongoDBInstancesManager)
67+
? (new TestMongoDBInstanceManager() as unknown as MongoDBInstancesManager)
6768
: null
6869
);
6970

0 commit comments

Comments
 (0)