當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ava類代碼示例

本文整理匯總了TypeScript中ava的典型用法代碼示例。如果您正苦於以下問題:TypeScript ava類的具體用法?TypeScript ava怎麽用?TypeScript ava使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ava類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

import * as test from "ava";
import { factorial } from "../model/utils";

test("factorial", t => {
	t.is(factorial(0), 1);
	t.is(factorial(1), 1);
	t.is(factorial(2), 2);
	t.is(factorial(3), 6);
	t.is(factorial(4), 24);
});
開發者ID:PacktPublishing,項目名稱:TypeScript-Blueprints,代碼行數:10,代碼來源:utils.ts

示例2: res

import dispatch from '../../lib/middleware/dispatch';
import * as test from 'ava';
import { app } from '../fixtures/overland';
import MyCtrl from '../fixtures/ctrl';
import * as Router from 'koa-router';

test('should invoke action', async function(t) {
  app.controllers.set('myApp.myCtrl', MyCtrl);
  const res = dispatch(app, 'myApp.myCtrl', 'index', {});  
  const ctx = { body: '', router: new Router() };
  await res(ctx);
  t.same(ctx.body, 'Hello, world.');
});
開發者ID:gitter-badger,項目名稱:overland,代碼行數:13,代碼來源:dispatch.ts

示例3: function

import { Router } from '../../core';
import * as test from 'ava';

test(`should generate url helpers`, async function(t) {
  
  const r1 = new Router();
  r1.app = 'myApp';
  r1.resources('posts', { controller: 'post' }); 
  
  const r2 = new Router();
  r2.use('myApp', r1);
  
  t.ok(Object.keys(r2.helpers), [ 'myAppPosts', 'myAppNewPost', 'myAppEditPost', 'myAppPost' ]);
});
開發者ID:gitter-badger,項目名稱:overland,代碼行數:14,代碼來源:routes.ts

示例4: Router

import * as test from 'ava';
import MyApp from '../fixtures/app';
import { App } from '../../core';
import { Router } from '../../core';
import { app as overland } from '../fixtures/overland';

test(`should have a readable/writeable 'app' property`, t => {
  const MyApp2 = Object.create(MyApp);
  MyApp2.app = 'Foobar';
  t.not(MyApp2.app, MyApp.app);
});

test(`'app' property should default to name of the constructor`, t => {
  t.is(MyApp.app, 'myBlog');
})

test(`should have a readable/writeable 'routes' property`, t => {
  const MyApp2 = Object.create(MyApp);
  MyApp2.routes = new Router();
  t.not(MyApp.routes, MyApp2.routes);
});

test(`should have a readable/writeable 'controllers' property`, t => {
  const MyApp2 = Object.create(MyApp);
  MyApp2.controllers = [];
  t.not(MyApp.controllers, MyApp2.controllers);
});

test(`should have a readable/writeable 'model' property`, t => {
  const MyApp2 = Object.create(MyApp);
  MyApp2.models = [];
開發者ID:gitter-badger,項目名稱:overland,代碼行數:31,代碼來源:app.ts

示例5:

import * as test from 'ava';
import { Model } from 'objection';
import * as Models from '../fixtures/models';
import Migration from '../../lib/db/migration';
import * as Knex from 'knex';

test('should set tableName to function ctor name', t => {
  t.is(Models.One.tableName, 'myBlog_One');
});

test('should allow tableName to be set manually', t => {
  const M2 = Object.create(Models.One);
  M2.tableName = 'foobar';
  t.is(M2.tableName, 'foobar');
})

test('should generate ManyToMany relation mappings', t => {
  const actual = Models.Four.relationMappings;
  const expected = {
    modelClass: Models.Two,
    relation: Model.ManyToManyRelation,
    join: {
      from: 'myBlog_Four.id',
      to: 'myBlog_Two.myId',
      through: {
        modelClass: undefined,
        from: 'myBlog_Four_Two.fourId',
        to: 'myBlog_Four_Two.twoId'
      }
    }
  };
開發者ID:gitter-badger,項目名稱:overland,代碼行數:31,代碼來源:model.ts

示例6: function

import { app } from '../fixtures/overland';
import MyApp from '../fixtures/app';
import Overland, { Router } from '../../core';
import { redirectTo } from '../../lib/helpers';
import * as test from 'ava';

test(`should generate a url from a model instance`, async function(t) {
  const res = await app.init()
  const r = redirectTo.bind(res);
  const Ctor = res.modelConstructors()[4];
  const instance = new Ctor({ id: 2 });
  const out = r(instance);
  t.same(out, '/app/posts/2');
});
開發者ID:gitter-badger,項目名稱:overland,代碼行數:14,代碼來源:redirectTo.ts

示例7: override

import * as test from 'ava';
import { app } from '../fixtures/overland';
import MyCtrl from '../fixtures/ctrl';
import { request } from 'http';

test('should override provided method', async function(t) {
  
  await app.init();
  
  const ctx = {
    method: 'post',
    request: {
      body: { _method: 'patch' }
    }
  };
  
  let method;
  
  await override()(ctx, async function() {
    return async function(ctx) {
      method = ctx.method;
    }(ctx);
  });
  
  t.same(method, 'patch');
});

test('should ignore requests without request bodies', async function(t) {
  
  await app.init();
  
開發者ID:gitter-badger,項目名稱:overland,代碼行數:30,代碼來源:override.ts

示例8: cb

    const obj = {};
    q.forEach(q => obj[q.name] = true);
    cb(obj);
  });
});

test(`should correctly determine a table drop.`, async function(t) {

  const m = new Migration(drop.one, drop.two);

  t.same(await m.schema(), {
    models: {
      added: {},
      altered: {},
      deleted: {
        test_table: true
      }
    },
    fields: {
      added: {},
      altered: {},
      deleted: {}
    }
  });
});

test(`should correctly determine a table rename.`, async function(t) {

  const m = new Migration(rename.one, rename.two);

  t.same(await m.schema(), {
開發者ID:gitter-badger,項目名稱:overland,代碼行數:31,代碼來源:modelSchema.ts

示例9: cb

    const obj = {};
    q.forEach(q => obj[q.name] = true);
    cb(obj);
  });
});

test(`should correctly determine a field drop`, async function(t) {
  
  const m = new Migration(drop.one, drop.two);
  
  t.same(await m.schema(), {
    models: {
      added: {},
      altered: {},
      deleted: {}
    },
    fields: {
      added: {},
      altered: {},
      deleted: {
        test_table: { myText: true }
      }
    }
  });
});

test(`should correctly determine a field rename`, async function(t) {
  const m = new Migration(rename.one, rename.two);
  
  t.same(await m.schema(), {
    models: {
開發者ID:gitter-badger,項目名稱:overland,代碼行數:31,代碼來源:fieldSchema.ts

示例10:

  t.context.log = console.log; 
  console.log = sinon.spy();
});

test.afterEach(t => {
  console.log = t.context.log;
});

test(`Should filter field props out of table.`, t => {
  const res = Migration.filterFields({
    app: 'myApp',
    tableName: 'myApp_foo',
    name: 'foo',
    fields: [
      { name: 'bar' },
      { name: 'baz' }
    ]
  })
  t.same(res, {
    app: 'myApp',
    tableName: 'myApp_foo',
    name: 'foo'
  });
});


test(`Should filter field props out of an array of tables.`, t => {
  const res = Migration.filterFields([{
    app: 'myApp',
    tableName: 'myApp_foo',
    name: 'foo',
    fields: [
開發者ID:gitter-badger,項目名稱:overland,代碼行數:32,代碼來源:migration.ts


注:本文中的ava類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。