Skip to content
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

Merged
merged 7 commits into from
May 11, 2018
Merged

Add jest matcher #150

merged 7 commits into from
May 11, 2018

Commits on May 9, 2018

  1. Add jest matcher

    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();
    });
    
    ```
    a-xin committed May 9, 2018
    Configuration menu
    Copy the full SHA
    4f3fc3b View commit details
    Browse the repository at this point in the history

Commits on May 10, 2018

  1. Clean-up jest plugin

    a-xin committed May 10, 2018
    Configuration menu
    Copy the full SHA
    4ba2c43 View commit details
    Browse the repository at this point in the history
  2. Add tests for jest plugin

    a-xin committed May 10, 2018
    Configuration menu
    Copy the full SHA
    47a92c5 View commit details
    Browse the repository at this point in the history
  3. Add docs for jest plugin

    a-xin committed May 10, 2018
    Configuration menu
    Copy the full SHA
    d417e7c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    170e1a7 View commit details
    Browse the repository at this point in the history
  5. Run jest plugin tests on travis

    As jest requires node v6+ don't run tests if a version lower than 6 is
    detected.
    a-xin committed May 10, 2018
    Configuration menu
    Copy the full SHA
    e9db456 View commit details
    Browse the repository at this point in the history

Commits on May 11, 2018

  1. Use grep to check node version

    Using grep is less future-proof but the better option, as comparing
    using `<` can be incorrect.
    a-xin committed May 11, 2018
    Configuration menu
    Copy the full SHA
    396bd0d View commit details
    Browse the repository at this point in the history