diff --git a/.changeset/happy-planets-lick.md b/.changeset/happy-planets-lick.md new file mode 100644 index 00000000000..214226191d9 --- /dev/null +++ b/.changeset/happy-planets-lick.md @@ -0,0 +1,5 @@ +--- +"@firebase/rules-unit-testing": patch +--- + +Fix assertFails not correctly catching RTDB permission denied errors (#4667). diff --git a/packages/rules-unit-testing/src/api/index.ts b/packages/rules-unit-testing/src/api/index.ts index 0ea93425c24..f5138d52505 100644 --- a/packages/rules-unit-testing/src/api/index.ts +++ b/packages/rules-unit-testing/src/api/index.ts @@ -583,7 +583,8 @@ export function assertFails(pr: Promise): any { const isPermissionDenied = errCode === 'permission-denied' || errCode === 'permission_denied' || - errMessage.indexOf('permission_denied') >= 0; + errMessage.indexOf('permission_denied') >= 0 || + errMessage.indexOf('permission denied') >= 0; if (!isPermissionDenied) { return Promise.reject( diff --git a/packages/rules-unit-testing/test/database.test.ts b/packages/rules-unit-testing/test/database.test.ts index eab354c9cf8..7117f1bc233 100644 --- a/packages/rules-unit-testing/test/database.test.ts +++ b/packages/rules-unit-testing/test/database.test.ts @@ -128,6 +128,31 @@ describe('Testing Module Tests', function () { .catch(() => {}); }); + it('assertFails() if message is Permission denied', async function () { + const success = Promise.resolve('success'); + const permissionDenied = Promise.reject({ + message: 'Permission denied' + }); + const otherFailure = Promise.reject('failure'); + await firebase + .assertFails(success) + .then(() => { + throw new Error('Expected success to fail.'); + }) + .catch(() => {}); + + await firebase.assertFails(permissionDenied).catch(() => { + throw new Error('Expected permissionDenied to succeed.'); + }); + + await firebase + .assertFails(otherFailure) + .then(() => { + throw new Error('Expected otherFailure to fail.'); + }) + .catch(() => {}); + }); + it('discoverEmulators() finds all running emulators', async () => { const options = await firebase.discoverEmulators();