本文整理汇总了TypeScript中@angular/core/testing.afterEach函数的典型用法代码示例。如果您正苦于以下问题:TypeScript afterEach函数的具体用法?TypeScript afterEach怎么用?TypeScript afterEach使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了afterEach函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('Service: LocalStorage', () => {
beforeEach(() => {
addProviders([LocalStorageService]);
window.localStorage.clear();
});
afterEach(() => {
window.localStorage.clear();
});
it('exists',
inject([LocalStorageService],
(service: LocalStorageService) => {
expect(service).toBeTruthy();
}));
it('stores items in localStorage',
inject([LocalStorageService],
(service: LocalStorageService) => {
let item = { key: 'value' };
service.setItem(mockStorageKey, item);
expect(window.localStorage.getItem(mockStorageKey)).toEqual(item);
}));
it('gets items from localStorage',
inject([LocalStorageService],
(service: LocalStorageService) => {
let item = { key: 'value' };
window.localStorage.setItem(mockStorageKey, JSON.stringify(item));
expect(service.getItem(mockStorageKey)).toEqual(item);
}));
});
示例2: describe
describe('platform-server integration', () => {
afterEach(() => disposePlatform());
it('should bootstrap', async(() => {
var body = writeBody('<app></app>');
serverBootstrap(MyServerApp).then(() => {
expect(getDOM().getText(body)).toEqual('Works!');
});
}));
});
示例3: describe
describe('platform-server integration', () => {
beforeEach(() => disposePlatform());
afterEach(() => disposePlatform());
it('should bootstrap', async(() => {
var body = writeBody('<app></app>');
serverBootstrap(MyServerApp, [
BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS
]).then(() => { expect(getDOM().getText(body)).toEqual('Works!'); });
}));
});
示例4: describe
describe('title service', () => {
var initialTitle = getDOM().getTitle();
var titleService = new Title();
afterEach(() => { getDOM().setTitle(initialTitle); });
it('should allow reading initial title',
() => { expect(titleService.getTitle()).toEqual(initialTitle); });
it('should set a title on the injected document', () => {
titleService.setTitle('test title');
expect(getDOM().getTitle()).toEqual('test title');
expect(titleService.getTitle()).toEqual('test title');
});
it('should reset title to empty string if title not provided', () => {
titleService.setTitle(null);
expect(getDOM().getTitle()).toEqual('');
});
});
示例5: describe
describe('With DefaultDriverType', function() {
const TEST_KEY = `${CUSTOM_NAMESPACE}-${Math.random() * 1000}`
beforeEachProviders(() => [provide(LockerConfig, {useValue: new LockerConfig(null, driver)}), Locker])
afterEach(() => driver.clear())
it(`sets driver to ${driverName}`, inject([Locker, LockerConfig], function(locker: Locker) {
expect(locker['driver']).toEqual(driver)
}))
it('sets key with string value into storage', inject([Locker], function(locker: Locker) {
const TEST_VALUE = 'TEST'
locker.set(TEST_KEY, TEST_VALUE)
expect(locker.get(TEST_KEY)).toEqual(TEST_VALUE)
}))
it('sets key with object value into storage', inject([Locker], function(locker: Locker) {
const TEST_VALUE = {
object1: 'villa',
myObject: 'Test'
}
locker.set(TEST_KEY, TEST_VALUE)
expect(locker.get(TEST_KEY)).toEqual(TEST_VALUE)
}))
it('removes data from storage with .remove', inject([Locker], function(locker: Locker) {
const TEST_VALUE = 'TEST'
locker.set(TEST_KEY, TEST_VALUE)
locker.remove(TEST_KEY)
expect(locker.get(TEST_KEY)).not.toEqual(TEST_VALUE)
}))
it('clears all data from the storage with .clear', inject([Locker], function(locker: Locker) {
const TEST_VALUE = 'TEST',
TEST_KEY_2 = `TEST_${TEST_KEY}`
locker.set(TEST_KEY, TEST_VALUE)
locker.set(TEST_KEY_2, TEST_VALUE)
locker.clear()
expect(locker.get(TEST_KEY)).not.toEqual(TEST_VALUE)
expect(locker.get(TEST_KEY_2)).not.toEqual(TEST_VALUE)
}))
it('can fetch key by index', inject([Locker], function(locker: Locker) {
var dummy = {
key: 'TEST',
data: `TEST-${Math.random() * 1000}`
}
locker.set(dummy.key, dummy.data)
expect(locker.key()).toEqual(dummy.key)
}))
})
示例6: describe
describe('Page1Service standalone TEST ' + '-'.repeat(40), () => {
let service: Page1Service;
let clock: lolex.Clock;
beforeEachProviders(() => [
Page1Service,
]);
beforeEach(inject([Page1Service], (_service) => {
service = _service;
}));
afterEach(() => {
try {
clock.uninstall();
} catch (e) { }
});
it('can create', asyncPower(async () => {
assert(!!service);
}));
// このテストはfakeAsyncテストでは通らない。asyncテストでもsetTimeoutしないと通らない。
// ServiceからsetInterval(Observable.timer)を取り除けばこんなややこしいことをしなくてもテストが通る。
it('counter value must be increment correctly', asyncPower(async () => {
await setTimeoutPromise(0, true); // setTimeoutしてzoneのfirst turnから抜けた状態じゃないと下記のテストは通らない。
assert(observableValue(service.counter$) === 0);
service.increment(1);
assert(observableValue(service.counter$) === 1);
service.increment(1);
assert(observableValue(service.counter$) === 2);
service.increment(2);
assert(observableValue(service.counter$) === 4);
}));
// らこさんエディション
it('counter value must be increment correctly by @laco', async(() => {
let value: number;
service.counter$.subscribe(counter => value = counter);
setTimeout(() => {
service.increment(1);
assert(value === 1);
service.increment(1);
assert(value === 2);
service.increment(2);
assert(value === 4);
}, 0);
}));
it('exprimental 2', asyncPower(async () => {
await setTimeoutPromise(0, true);
let counter: number;
let currentTime: number;
let previousTime: number;
service.counter$.subscribe(value => counter = value);
service.timeNow$.subscribe(value => {
if (currentTime) {
previousTime = currentTime;
}
currentTime = value;
});
service.increment(1);
assert(counter === 1);
service.increment(1);
assert(counter === 2);
service.increment(2);
assert(counter === 4);
await setTimeoutPromise(1000);
console.log([previousTime, currentTime]);
assert(previousTime + 1000 <= currentTime);
}));
});