title: How to test objection.js with jest?
body: <pre><code>Model.knex(knex);
  
  const app = express();
  
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  
  app.use(i18nextMiddleware);
  </code></pre>
  
  <p>I want to test method getUsers of users controller. It get data from usersModel getUsers method. I get date from MySQL by Objections ORM. </p>
  
  <pre><code>app.get(
    '/',
    checkFilter(['type']),
    users.getUsers
  );
  </code></pre>
  
  <p>According to instructions, I am changing the query method.</p>
  
  <pre><code>class MyQueryBuilder extends QueryBuilder {
    query() {
      return this.resolve({ test: 11111 });
    }
  }
  
  class UsersModel extends Model {
    static get QueryBuilder() {
      return MyQueryBuilder;
    }
  }
  
  jest.spyOn(Users, 'query')
    .mockImplementation(UsersModel.query);
  </code></pre>
  
  <p>Describe test.</p>
  
  <pre><code>describe('get errors', () =&gt; {
    beforeAll(done =&gt; {
      i18next.on('initialized', () =&gt; {
        done()
      });
    });
  
    it('with filter', done =&gt; {
      request(app)
        .get('/')
        .query({page: 0, perPage: 5, type: 'admin'})
        .end((err, res) =&gt; {
          if (err) return done(err);
  
          expect(res.status).toBe(200);
          expect(
            Object.keys(res.body).sort()
          ).toEqual([
            'items',
            'itemsOnPage',
            'currentPage',
            'totalPage',
            'totalItems'
          ].sort());
          expect(res.body.items).toHaveLength(8);
          expect(res.body.totalItems).toBe(usersMockDB.getUsers.length);
  
          console.log(res.body);
  
          done();
        });
    });
  
    afterAll(done =&gt; {
      knex.destroy();
  
      done();
    })
  });
  
  </code></pre>
  
  <p>Method getUsers of users model.</p>
  
  <pre><code>    const { Users } = require('../../db/models/Users');
  
      const query = Users
        .query()
        .select(
          'id',
          'login',
          'type',
          'edit',
          'email',
          'phone',
          'block'
        )
        .orderBy('id', 'DESC')
        .page(page, perPage);
  
      // filter
  
      if (Object.keys(usersFilter).length) {
        for (let field in usersFilter) {
          if ( usersFilter.hasOwnProperty(field) ) {
            query.where(field, 'like', `%${ usersFilter[field] }%`);
          }
        }
      }
  
      const { results, total } = await query;
  
      return {
        items:       results,
        itemsOnPage: Number(perPage),
        currentPage: Number(page),
        totalPage:   Math.ceil(total/perPage),
        totalItems:  Number(total)
      }
  </code></pre>
  
  <p>Should I override methods page and where ? As I understand it, they make new database queries.</p>