-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add jest matcher #150
Add jest matcher #150
Conversation
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(); }); ```
@dinoboff What do you think of the approach and the interfaces? Happy to add tests and docs if the code looks fine |
Thanks, I like the interface. I will include once there are integration test and documentation similar to the Jasmine plugin. Note that |
Also, in v4, I might move the plugins to their own packages. Core and plugins will still be hosted together in that repo. |
Good shout about node 4! With jest supporting only 6+ out of the box, it would make sense to put the plugin into a separate package right away and have it require node 6+. |
As jest requires node v6+ don't run tests if a version lower than 6 is detected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
Thanks!
.travis.yml
Outdated
@@ -11,3 +11,9 @@ script: | |||
fi | |||
- npm run coveralls | |||
- npm run lint | |||
- > | |||
if [[ $(node --version | cut -c 2-) < 6 ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change the version test. Either use grep
or change the previous test to use cut
. cut
is probably better.
Using grep is less future-proof but the better option, as comparing using `<` can be incorrect.
Thanks @a-xin. Published with |
Adding jest matchers to conveniently use targaryen with jest.
See #129
Usage:
or using the generic matcher: