Skip to content

Commit e749ab8

Browse files
Fix assertFails() logic of @firebase/rules-unit-testing (#3676)
* Fix assertFails logic * Create fuzzy-seas-compare.md Co-authored-by: Yuchen Shi <[email protected]>
1 parent c224553 commit e749ab8

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

.changeset/fuzzy-seas-compare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/rules-unit-testing": patch
3+
---
4+
5+
Fix assertFails() logic of @firebase/rules-unit-testing

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ export function assertFails(pr: Promise<any>): any {
328328
},
329329
(err: any) => {
330330
const isPermissionDenied =
331-
err && err.message && err.message.indexOf('PERMISSION_DENIED') >= 0;
331+
(err && err.message && err.message.indexOf('PERMISSION_DENIED') >= 0) ||
332+
(err && err.code === 'permission-denied');
332333
if (!isPermissionDenied) {
333334
return Promise.reject(
334335
new Error(

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

+25
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@ describe('Testing Module Tests', function () {
6767
.catch(() => {});
6868
});
6969

70+
it('assertFails() if code is permission-denied', async function () {
71+
const success = Promise.resolve('success');
72+
const permissionDenied = Promise.reject({
73+
code: 'permission-denied'
74+
});
75+
const otherFailure = Promise.reject('failure');
76+
await firebase
77+
.assertFails(success)
78+
.then(() => {
79+
throw new Error('Expected success to fail.');
80+
})
81+
.catch(() => {});
82+
83+
await firebase.assertFails(permissionDenied).catch(() => {
84+
throw new Error('Expected permissionDenied to succeed.');
85+
});
86+
87+
await firebase
88+
.assertFails(otherFailure)
89+
.then(() => {
90+
throw new Error('Expected otherFailure to fail.');
91+
})
92+
.catch(() => {});
93+
})
94+
7095
it('initializeTestApp() with auth=null does not set access token', async function () {
7196
const app = firebase.initializeTestApp({
7297
projectId: 'foo',

0 commit comments

Comments
 (0)