本文整理汇总了TypeScript中ava.test.beforeEach方法的典型用法代码示例。如果您正苦于以下问题:TypeScript test.beforeEach方法的具体用法?TypeScript test.beforeEach怎么用?TypeScript test.beforeEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ava.test
的用法示例。
在下文中一共展示了test.beforeEach方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: helper
import * as mst from "mobx-state-tree"
import { test } from "ava"
import * as sinon from "sinon"
import { simpleActionLogger } from "../src"
test.beforeEach(t => {
t.context.log = console.log
console.log = sinon.spy()
})
test.afterEach(t => {
console.log = t.context.log
})
test("it logs", t => {
const Todo = mst.types
.model({
title: ""
})
.actions(self => ({
helper() {},
setTitle(newTitle) {
;(self as any).helper() // should not be logged
self.title = newTitle
}
}))
const Store = mst.types.model({
todos: mst.types.array(Todo)
})
示例2: require
}
},
upperGreet: 'Hello {name:format:uppercase}',
lowerGreet: 'Hello {name:format:lowercase}',
titleGreet: 'Hello {name:format:title}',
denormCap: 'Hello {name:format:denormalize,uppercase}'
};
test.before(() => {
global.Intl = require('intl');
});
test.beforeEach(t => {
t.context.chomsky = new Chomsky();
t.context.chomsky.dictionaryManager.add('fr', FR_TRANSLATIONS);
t.context.chomsky.dictionaryManager.add('en', US_TRANSLATIONS);
sinon.stub(t.context.chomsky, 'getTranslations', () => { return Observable.of({ KEY: 'value' }); });
sinon.stub(t.context.chomsky.loader, 'load', () => { return Observable.of({ KEY: 'value' }); });
});
// setLocation(location)
test('setLocation should set the location', t => {
t.context.chomsky.setLocation('LOCATION');
t.is(t.context.chomsky.location, 'LOCATION');
});
// setDefaultReplacements(replacements);
test('setDefaultReplacements should set the replacements', t => {
t.context.chomsky.setDefaultReplacements('REPLACEMENTS');
示例3: BudgetContext
import * as ava from "ava";
import * as moment from "moment";
import BudgetContext from "../client/data/budgetcontext";
import Expense from "../client/expenses/expense";
import * as it from "../client/rates/intervaltype";
import Rate from "../client/rates/rate";
import {ExpenseDataSource, ExpenseController} from "../client/expenses/expensecontroller";
ava.test.beforeEach(t => {
t.context.budgetContext = new BudgetContext();
});
ava.test("update", t => {
let bc = t.context.budgetContext;
let date = moment([2016, 0, 5]);
let controller = new ExpenseController(bc, date);
t.is(controller.vm.list().length, 0);
bc.addExpense(new Expense("test", date, -25));
t.is(controller.vm.list().length, 1);
t.is(controller.vm.list()[0].id(), 1);
t.is(controller.vm.total(), -25);
controller.vm.remove(1);
t.is(controller.vm.list().length, 0);
});
ava.test("add", t => {
let bc = t.context.budgetContext;
let date = moment([2016, 0, 5]);
let controller = new ExpenseController(bc, date);
示例4: DictionaryManager
import { test } from 'ava';
import { DictionaryManager } from './dictionary-manager';
test.beforeEach(t => {
t.context.manager = new DictionaryManager();
});
// Method Checking
test('should be defined', t => {
t.truthy(t.context.manager);
});
test('should have a method contains', t => {
t.truthy(t.context.manager.contains);
});
test('should have a method get', t => {
t.truthy(t.context.manager.get);
});
test('should have a method add', t => {
t.truthy(t.context.manager.add);
});
// contains(key)
test('contains should return true if it contains the locale', t => {
t.context.manager.dictionaries = { test: {} };
t.true(t.context.manager.contains('test'));
});
示例5: constructor
import { test } from 'ava';
import { AstServiceParser } from './AstServiceParser';
class TestAstServiceParser extends AstServiceParser {
/*public getInstancePropertyName(): string {
return this._getInstancePropertyName();
}*/
}
const componentFilename: string = 'test.component.ts';
let parser: TestAstServiceParser;
test.beforeEach(() => {
parser = new TestAstServiceParser();
});
test('should extract strings in TranslateService\'s get() method', async t => {
const contents = `
@Component({ })
export class AppComponent {
public constructor(protected _translateService: TranslateService) { }
public test() {
this._translateService.get('Hello World');
}
`;
const keys = parser.extract(contents, componentFilename).keys();
t.deepEqual(keys, ['Hello World']);
});
test('should extract strings in TranslateService\'s instant() method', async t => {
const contents = `
示例6: require
import { test } from 'ava';
const sinon = require('sinon'); // Require because this package does not support commonjs modules
import { Loader } from './loader';
let server;
test.beforeEach(t => {
t.context.loader = new Loader();
server = sinon.fakeServer.create();
});
test.afterEach(() => {
server.restore();
});
// Method Checking
test('should be defined', t => {
t.truthy(t.context.loader);
});
test('should have a method load', t => {
t.truthy(t.context.loader.load);
});
// load(url)
test('load should properly load a json file', t => {
let valid = { KEY: 'value' };
t.context.loader.load('/valid.json').then(result => {
t.deepEqual(result, valid);
示例7: require
long: '4 décembre 1987 à 12:00',
dateShort: '04/12/1987',
dateMedium: '4 déc. 1987',
dateLong: '4 décembre 1987',
timeShort: '12:00',
timeLong: '12:00 '
}
};
test.before(() => {
global.Intl = require('intl');
});
test.beforeEach(t => {
t.context.formats = new Formats();
// Provide the DEFAULT overrides
t.context.formats.override(FORMAT_DEFAULTS);
});
// Method Checking
test('should have overrides defined', t => {
t.truthy(t.context.formats.override);
});
test('should have setLocale defined', t => {
t.truthy(t.context.formats.setLocale);
});
test('should have formatNumber defined', t => {
t.truthy(t.context.formats.formatNumber);
示例8: BudgetContext
import * as ava from "ava";
import * as moment from "moment";
import BudgetContext from "../client/data/budgetcontext";
import Expense from "../client/expenses/expense";
import * as it from "../client/rates/intervaltype";
import Rate from "../client/rates/rate";
import {RateDataSource, RateController} from "../client/rates/ratecontroller";
ava.test.beforeEach(t => {
t.context.budgetContext = new BudgetContext();
t.context.date = moment([2016, 0, 5]);
t.context.controller = new RateController(t.context.budgetContext,
t.context.date);
});
ava.test("update", t => {
let bc: BudgetContext = t.context.budgetContext;
let date = t.context.date;
let controller: RateController = t.context.controller;
t.is(controller.vm.list().length, 0);
bc.addRate(new Rate("test", -25, 1, it.IntervalType.Days, date));
t.is(controller.vm.list().length, 1);
});
ava.test("add", t => {
let bc: BudgetContext = t.context.budgetContext;
let date = t.context.date;
let controller: RateController = t.context.controller;