Skip to content

Commit b4d647b

Browse files
committed
Fix assert fails (firebase#4667)
1 parent a4b794b commit b4d647b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/rules-unit-testing/src/api/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ export function assertFails(pr: Promise<any>): any {
583583
const isPermissionDenied =
584584
errCode === 'permission-denied' ||
585585
errCode === 'permission_denied' ||
586-
errMessage.indexOf('permission_denied') >= 0;
586+
errMessage.indexOf('permission_denied') >= 0 ||
587+
errMessage.indexOf('permission denied') >= 0;
587588

588589
if (!isPermissionDenied) {
589590
return Promise.reject(

packages/rules-unit-testing/test/database.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,31 @@ describe('Testing Module Tests', function () {
128128
.catch(() => {});
129129
});
130130

131+
it('assertFails() if message is Permission denied', async function () {
132+
const success = Promise.resolve('success');
133+
const permissionDenied = Promise.reject({
134+
message: 'Permission denied'
135+
});
136+
const otherFailure = Promise.reject('failure');
137+
await firebase
138+
.assertFails(success)
139+
.then(() => {
140+
throw new Error('Expected success to fail.');
141+
})
142+
.catch(() => {});
143+
144+
await firebase.assertFails(permissionDenied).catch(() => {
145+
throw new Error('Expected permissionDenied to succeed.');
146+
});
147+
148+
await firebase
149+
.assertFails(otherFailure)
150+
.then(() => {
151+
throw new Error('Expected otherFailure to fail.');
152+
})
153+
.catch(() => {});
154+
});
155+
131156
it('discoverEmulators() finds all running emulators', async () => {
132157
const options = await firebase.discoverEmulators();
133158

0 commit comments

Comments
 (0)