tachybase_todo/docs/cores/packages/test.md
chenos d5d0e1036b
docs: add docs (#75)
* docs: add docs

* ignore dumi theme test

* fix: error TS2717: Subsequent property declarations must have the same type.

* update docs

* deploy gh-pages

* plugins docs

* hash & cname

* exportStatic

* ssr

* vercel

* vercel

* fix: deploy vercel

* Delete vercel.json

* docs

* fix APP_DIST

* on master branch
2021-04-17 21:33:21 +08:00

1.1 KiB
Raw Blame History

title order
@nocobase/test 7

@nocobase/test

mockDatabase

为 database 提供的测试套件,同时提供数据 mock使用 mockjs

import { mockDatabase } from '@nocobase/test';

describe('test', () => {
  let db;

  beforeEach(async () => {
    db = mockDatabase({});
    db.table({
      name: 'examples',
      fields: [{
        name: 'name',
        type: 'string',
        mock: {
          "1-10": "★"
        },
      }],
    });
    await db.sync();
  });

  afterEach(async () => {
    await db.close();
  });

  it('test model', () => {
    const Test = db.getModel('tests');
    Test.mockCreate({});
    Test.mockBulkCreate([{}]);
  });
});

mockServer

为 server 提供的测试套件

import { mockServer } from '@nocobase/test';

describe('test', () => {
  let api;

  beforeEach(async () => {
    api = mockServer({});
    await api.database.sync();
  });

  afterEach(async () => {
    await api.database.close();
  });

  it('test resource', () => {
    await api.resource('demos').get();
  });

  it('test request', () => {
    await api.request().get('/');
  });
});