Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding jest matchers to conveniently use targaryen with jest. Usage: ``` const { getDatabase, toAllowRead, toAllowUpdate, toAllowWrite, json } = require('targaryen/plugins/jest'); expect.extend({ toAllowRead, toAllowUpdate, toAllowWrite, }); const RULES_PATH = 'database.rules.json'; const rules = json.loadSync(RULES_PATH); const initialData = {}; const database = getDatabase(rules, initialData); test('basic', () => { expect(database.as(null)).not.toAllowRead('/user'); expect(database.as(null)).toAllowRead('/public'); expect(database.as({ uid: '1234'})).toAllowWrite('/user/1234', { name: 'Anna', }); }); ``` or using the generic matcher: ``` const { getDebugDatabase, toBeAllowed, json } = require('targaryen/plugins/jest'); expect.extend({ toBeAllowed, }); const RULES_PATH = 'database.rules.json'; const rules = json.loadSync(RULES_PATH); const initialData = {}; // NOTE: Create a database with debug set to true for detailed errors const database = getDebugDatabase(rules, initialData); test('generic', () => { expect(database.as(null).read('/user')).not.toBeAllowed(); expect(database.as({ uid: '1234' }).write('/user/1234', { name: 'Anna', })).toBeAllowed(); }); ```
- Loading branch information