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


TypeScript ava.afterEach函數代碼示例

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


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

示例1:

      explanation: "Wanna stay in touch?",
    },
    unsubscribeEnabled: true,
  };

  await TestEnvironment.initialize({
    addPrompts: true,
    httpOrHttps: HttpHttpsEnvironment.Https,
  });
  TestEnvironment.mockInternalOneSignal();
  sandbox.stub(OneSignal.context.dynamicResourceLoader, 'loadSdkStylesheet')
    .returns(ResourceLoadState.Loaded);
});

test.afterEach(function () {
  sandbox.restore();
});

test('customlink: container: not render if disabled', async t => {
  config = {
    enabled: false,
  };
  await CustomLink.initialize(config);

  const containerElements = document.querySelectorAll<HTMLElement>(CustomLink.containerSelector);
  t.is(containerElements.length, 2);
  containerElements.forEach((el: HTMLElement) => t.is(el.children.length, 0));
});

test('customlink: container: render if enabled, explanation present', async t => {
  sandbox.stub(OneSignal, 'privateIsPushNotificationsEnabled').returns(true);
開發者ID:OneSignal,項目名稱:OneSignal-Website-SDK,代碼行數:31,代碼來源:CustomLink.ts

示例2: require

import TestOut from './helpers/test_out'

const fetchMock = require('fetch-mock')
const debug = require('debug')('graphcool')

/*
 Tests:
- Succeeding project clone with specific name
- Succeeding project clone with specific name and different output path
- Succeeding project clone with specific name and project ID
- Succeeding project clone with specific name, project file and output path
- Failing because no project ID provided (no project file in current directory)
 */

test.afterEach(() => {
  new TestOut().write('\n')
  fetchMock.restore()
})


test('Succeeding project clone with specific name', async t => {

  // configure HTTP mocks
  fetchMock.post(systemAPIEndpoint, JSON.parse(mockedClonedProjectResponse))

  // create dummy project data
  const copyProjectId = 'abcdefghiklmn'
  const clonedProjectName = `Clone of MyProject`
  const props = {
    name: clonedProjectName,
    copyProjectId,
開發者ID:sadeeqaji,項目名稱:graphcool-cli,代碼行數:31,代碼來源:clone.test.ts

示例3: cb

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

test.beforeEach(t => {
  t.context.db = Knex({
    client: 'sqlite3',
    connection: {
      filename: ':memory:'
    }
  });
});

test.afterEach(async function(t) {
  await t.context.db.destroy();
});

test.serial(`should add table`, async function(t) {
  const r = new Migration(add.one, add.two);
  await Migration.run(t.context.db, await r.up());
  t.true(await t.context.db.schema.hasTable('test_table'));  
});

test.serial(`should drop table`, async function(t) {
  const m = new Migration(add.one, add.two);
  await Migration.run(t.context.db, await m.up(), await m.down());
  t.false(await t.context.db.schema.hasTable('test_table'));  
});

test.serial(`should rename table`, async function(t) {
開發者ID:gitter-badger,項目名稱:overland,代碼行數:31,代碼來源:model.ts

示例4: NullStorage

let data: history.HistoryElement;

test.beforeEach(t => {
  storage = new NullStorage();
  storageMock = sinon.mock(storage);
  historyStore = new history.HistoryStore(storage);
  data = {
    name: 'name',
    value: 'value',
    time: JSON.stringify(new Date())
  };
});

test.afterEach( t => {
  storage = null;
  storageMock = null;
  historyStore = null;
  data = null;
});

test('HistoryStore should be able to add an element in the history', t => {
  storageMock.expects('setItem').once().withArgs(history.STORE_KEY, sinon.match(/"value":"value"/).and(sinon.match(/"time"/)).and(sinon.match(/"internalTime"/)));
  historyStore.addElement(data);
  storageMock.verify();
});

test('History store should trim query over > 75 char', t => {
    data.value = '';
    let newValue = '';
    for (var i = 0; i < 100; i++) {
        newValue += i.toString();
    }
開發者ID:coveo,項目名稱:coveo.analytics.js,代碼行數:32,代碼來源:history_test.ts

示例5: Context

  sandbox = sinon.sandbox.create();

  await TestEnvironment.stubDomEnvironment();
  getRegistrationStub = sandbox.stub(navigator.serviceWorker, 'getRegistration').callThrough();

  const appConfig = TestEnvironment.getFakeAppConfig();
  appConfig.appId = Random.getRandomUuid();
  OneSignal.context = new Context(appConfig);

  // global assign required for TestEnvironment.stubDomEnvironment()
  (global as any).OneSignal = { context: OneSignal.context };
});

test.afterEach(function () {
  if (getRegistrationStub.callCount > 0)
    sandbox.assert.alwaysCalledWithExactly(getRegistrationStub, location.href);
  sandbox.restore();
});

test('getActiveState() detects no installed worker', async t => {
  const manager = LocalHelpers.getServiceWorkerManager();

  t.is(await manager.getActiveState(), ServiceWorkerActiveState.None);
});

test('getActiveState() detects worker A, case sensitive', async t => {
  await navigator.serviceWorker.register('/Worker-A.js');

  const manager = LocalHelpers.getServiceWorkerManager();
  t.is(await manager.getActiveState(), ServiceWorkerActiveState.WorkerA);
});
開發者ID:OneSignal,項目名稱:OneSignal-Website-SDK,代碼行數:31,代碼來源:ServiceWorkerManager.ts

示例6:

import sinon from 'sinon';
import SubscriptionHelper from '../../../src/helpers/SubscriptionHelper';
import { SubscriptionManager } from '../../../src/managers/SubscriptionManager';
import { SessionManager } from '../../../src/managers/SessionManager';

const sinonSandbox = sinon.sandbox.create();

test.beforeEach(async () => {
  await TestEnvironment.initialize({
    httpOrHttps: HttpHttpsEnvironment.Https
  });
  TestEnvironment.mockInternalOneSignal();
});

test.afterEach(() => {
  sinonSandbox.restore();
})

test('should not resubscribe user on subsequent page views if the user is already subscribed', async t => {
  sinonSandbox.stub(OneSignal, 'privateIsPushNotificationsEnabled').resolves(true);
  sinonSandbox.stub(SessionManager.prototype, 'getPageViewCount').returns(2);
  const subscribeSpy = sinonSandbox.spy(SubscriptionManager.prototype, 'subscribe');

  await SubscriptionHelper.registerForPush();
  t.true(subscribeSpy.notCalled);
});

test('should subscribe user on subsequent page views if the user is not subscribed', async t => {
  sinonSandbox.stub(OneSignal, 'isPushNotificationsEnabled').resolves(false);
  sinonSandbox.stub(SessionManager.prototype, 'getPageViewCount').returns(2);
  sinonSandbox.stub(SubscriptionManager.prototype, 'registerSubscription').resolves();
開發者ID:OneSignal,項目名稱:OneSignal-Website-SDK,代碼行數:31,代碼來源:subscriptionHelper.ts

示例7: Application

let pathToApp = `../../../../src/evetron/bin/${(process.platform === 'darwin'
    ? 'Electron.app/Contents/MacOS/'
    : '')}electron${(process.platform === 'win32'
        ? '.exe'
        : '')}`;

ava.beforeEach((test: any) => {
    test.context.app = new Application({
        path: pathToApp,
    });

    return test.context.app.start();
});

ava.afterEach((test: any) => {
    return test.context.app.stop();
});

ava((test: any) => {
    return test.context.app.client.waitUntilWindowLoaded()
        .getWindowCount().then((count: number) => {
            test.is(count, 1);
        }).browserWindow.isMinimized().then((min: boolean) => {
            test.false(min);
        }).browserWindow.isDevToolsOpened().then((opened: boolean) => {
            test.false(opened);
        }).browserWindow.isVisible().then((visible: boolean) => {
            test.true(visible);
        }).browserWindow.getBounds().then((bounds: any) => {
            test.true(bounds.width > 0);
            test.true(bounds.height > 0);
開發者ID:JimiC,項目名稱:evetron,代碼行數:31,代碼來源:main.ts

示例8: TestOut

import { Config } from '../src/utils/config'
import TestOut from './helpers/test_out'
import { graphcoolProjectFileName } from '../src/utils/constants'
import { testEnvironment } from './helpers/test_environment'
import { mockProjectFile1, mockProjectFileWithUppercaseAlias1 } from './fixtures/mock_data'
import { readProjectIdFromProjectFile } from '../src/utils/file'

/*
 Tests:
 - readProjectIdFromProjectFile with a file containing a project id
 - readProjectIdFromProjectFile with a file containing a project alias
 - readProjectIdFromProjectFile with a file missing a project id
 */

test.afterEach(() => {
  new TestOut().write('\n')
})

test('readProjectIdFromProjectFile with a file containing a project id', async t => {
  const env = testEnvironment({})
  env.resolver.write(graphcoolProjectFileName, mockProjectFile1)

  const project_id = readProjectIdFromProjectFile(env.resolver, graphcoolProjectFileName)

  t.is(project_id, 'abcdefghijklmn')
})

test('readProjectIdFromProjectFile with a file containing a project alias', async t => {
  const env = testEnvironment({})
  env.resolver.write(graphcoolProjectFileName, mockProjectFileWithUppercaseAlias1)
開發者ID:sadeeqaji,項目名稱:graphcool-cli,代碼行數:30,代碼來源:utils_file.test.ts

示例9: catch

import test from 'ava';
import * as moment from 'moment';
import { MongoClient, ObjectId } from 'mongodb';
import { promise as sleep } from 'es6-sleep';
import { MongoCron } from '..';

test.beforeEach(async (t) => {
  t.context.mongo = await MongoClient.connect('mongodb://localhost:27017', { useNewUrlParser: true });
  t.context.db = t.context.mongo.db('test');
  t.context.collection = t.context.db.collection('jobs');
  try { await t.context.collection.drop(); } catch (e) {}
});

test.afterEach(async (t) => {
  await t.context.mongo.close();
});

test.serial('document with `sleepUntil` should be processed', async (t) => {
  let times = 0;
  const c = new MongoCron({
    collection: t.context.collection,
    lockDuration: 0,
    onDocument: () => times++,
  });
  await t.context.collection.insertMany([
    { sleepUntil: new Date() },
    { sleepUntil: new Date() },
    { sleepUntil: null },
    { sleepUntil: new Date() },
  ]);
  await c.start();
開發者ID:xpepermint,項目名稱:mongodb-cron,代碼行數:31,代碼來源:cron.test.ts

示例10:

import { OneSignalUtils } from '../../../src/utils/OneSignalUtils';

let sinonSandbox: SinonSandbox;

test.beforeEach(async () => {
  sinonSandbox = sinon.sandbox.create();
  await TestEnvironment.initialize({
    httpOrHttps: HttpHttpsEnvironment.Https
  });

  // Required for sessionContext, not async
  TestEnvironment.mockInternalOneSignal();
});

test.afterEach(function (_t: TestContext) {
  sinonSandbox.restore();
});

test("getCurrentNotificationType for default permission", async t => {
  sinonSandbox.stub(OneSignal.context.permissionManager, "getNotificationPermission")
    .resolves(NotificationPermission.Default);
    
  t.is(await MainHelper.getCurrentNotificationType(), SubscriptionStateKind.Default);
});

test("getCurrentNotificationType for denied permission in HTTP context", async t => {
  sinonSandbox.stub(OneSignal.context.permissionManager, "getNotificationPermission")
    .resolves(NotificationPermission.Denied);
  sinonSandbox.stub(OneSignalUtils, "isUsingSubscriptionWorkaround").returns(true);

  t.is(await MainHelper.getCurrentNotificationType(), SubscriptionStateKind.Default);
開發者ID:OneSignal,項目名稱:OneSignal-Website-SDK,代碼行數:31,代碼來源:MainHelper.ts

示例11: InitTestHelper

import { UpdateManager } from '../../../src/managers/UpdateManager';
import PermissionManager from '../../../src/managers/PermissionManager';

const sinonSandbox: SinonSandbox = sinon.sandbox.create();
const initTestHelper = new InitTestHelper(sinonSandbox);
const playerId = Random.getRandomUuid();
const appId = Random.getRandomUuid();

test.beforeEach(function () {
  mockWebPushAnalytics();
});

test.afterEach(function (_t: TestContext) {
  sinonSandbox.restore();

  OneSignal._initCalled = false;
  OneSignal.__initAlreadyCalled = false;
  OneSignal._sessionInitAlreadyRunning = false;
});

/**
 * HTTP/HTTPS
 * 1. user not subscribed and not opted out
 *    1. first page view
 *     + 1. autoPrompt -> click allow -> player create
 *     + 2. autoPrompt -> click dismiss -> no requests
 *     + 3. autoResubscribe and permissions granted -> player create
 *     + 4. autoResubscribe and permissions default or blocked -> no requests
 *     + 5. no autoResubscribe and no autoPrompt -> no requests
 *    2. second page view - TODO
 * 2. user opted out
開發者ID:OneSignal,項目名稱:OneSignal-Website-SDK,代碼行數:31,代碼來源:onSession.ts

示例12: cb

test.before(t => {
  sinon.stub(inquirer, 'prompt', (q, cb) => {
    const obj = {};
    q.forEach(q => obj[q.name] = true);
    cb(obj);
  });
});

test.beforeEach(t => {
  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',
開發者ID:gitter-badger,項目名稱:overland,代碼行數:30,代碼來源:migration.ts

示例13: async

import InitHelper from "../../../src/helpers/InitHelper";
import OneSignalUtils from "../../../src/utils/OneSignalUtils";
import { TestEnvironment, BrowserUserAgent } from '../../support/sdk/TestEnvironment';
import { setBrowser } from '../../support/tester/browser';
import { stubMessageChannel } from '../../support/tester/utils';
import SubscriptionHelper from "../../../src/helpers/SubscriptionHelper";

let sandbox: SinonSandbox = sinon.sandbox.create();

test.beforeEach(async () => {
  await TestEnvironment.initialize();
  TestEnvironment.mockInternalOneSignal();
});

test.afterEach(() => {
  sandbox.restore();
});

/** registerForPushNotifications */
test('registerForPushNotifications: requesting a modal prompt', async (t) => {
  stubMessageChannel(t);

  await InitHelper.registerForPushNotifications({ modalPrompt: true });
  t.not(OneSignal.subscriptionModalHost, undefined);
  t.not(OneSignal.subscriptionModalHost.modal, undefined);
});

test('registerForPushNotifications: load fullscreen popup when using subscription workaround', async (t) => {

  const utilsStub = sandbox.stub(OneSignalUtils, 'isUsingSubscriptionWorkaround').returns(true);
  const loadStub = sandbox.stub(InitHelper, 'loadSubscriptionPopup').resolves();
開發者ID:OneSignal,項目名稱:OneSignal-Website-SDK,代碼行數:31,代碼來源:InitHelper.ts

示例14:

  t.context.expectedSafeHttpOriginsForIrregularSubdomains = [
    'http://dev.www.site.com',
    'https://dev.www.site.com',
  ];

  t.context.expectedSafeHttpOriginsForReallyIrregularSubdomains = [
    'http://dev.www2-6.en.site.com',
    'http://www.dev.www2-6.en.site.com',
    'https://dev.www2-6.en.site.com',
    'https://www.dev.www2-6.en.site.com',
  ];
});

test.afterEach(async t => {
  (global as any).MessageChannel = t.context.originalMessageChannel;
});

/*
  When a developer chooses a site URL to integrate HTTP web push, multiple
  variants of his site origin will support prompting the user to subscribe
  because the final subscription takes place outside of his site origins on our
  subdomain of .os.tc.

  If a developer chooses to integrate HTTP web push on 'http://site.com', for
  example, the prefix variants 'http://', 'http://www.', 'https://', and
  'https://www.' will all support prompting the user. The user will still be
  subscribed on subdomain.os.tc though, and not on any one of the listed
  origins.

  The above changes if the developer chooses to integrate HTTP web push on
開發者ID:OneSignal,項目名稱:OneSignal-Website-SDK,代碼行數:30,代碼來源:postmam.ts

示例15: fixture

const ftest = fixture(ava, 'fixtures/cases')

// ava.before(() => {
//   throw new Error('should not run before')
// })

ava.beforeEach(() => {
  throw new Error('should not run beforeEach')
})

// ava.after(() => {
//   throw new Error('should not run after')
// })

ava.afterEach(() => {
  throw new Error('should not run after each')
})

ava.skip('skip test', _t => {
  throw new Error('should not run ava skip')
})

ftest.skip('case-1', _t => {
  throw new Error('should not run ftest.skip')
})

ftest.skip.each(_t => {
  throw new Error('should not run')
})

ftest.skip.each.failing(_t => {
開發者ID:unional,項目名稱:ava-fixture,代碼行數:31,代碼來源:fixture.skip.spec.ts


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