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


TypeScript expect.createSpy函數代碼示例

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


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

示例1: getSpy

  private getSpy(targetKey: string): Spy<T> {
    if (!Reflect.hasMetadata(SPY_KEY, this.mock, targetKey)) {
      Reflect.defineMetadata(SPY_KEY, createSpy(), this.mock, targetKey);
    }

    return Reflect.getMetadata(SPY_KEY, this.mock, targetKey);
  }
開發者ID:otbe,項目名稱:emock,代碼行數:7,代碼來源:Mock.ts

示例2: getImageResponseMock

export function getImageResponseMock(): any {
  return {
    Architecture: 'amd64',
    Author: 'Brian Palmer <brian@codekitchen.net>',
    Config: {
      Cmd: [ 'bin', '-sh' ],
      Entrypoint: [ 'test1.sh', 'test2.sh' ],
      Env: [ 'TEST_VAR=5'],
      ExposedPorts: {
        '9000/tcp': null,
        '8080/udp': null,
      },
      User: 'TestUser',
      Volumes: {
        '/temp/tmp': null
      },
      WorkingDir: '/app'
    },
    Created: '2016-05-20T16:14:30.654638605Z',
    Id: 'sha256:9cfad7bf4e016fb7191140fb23537636bc186ffebff82e4f9b0a04422fcf1532',
    Os: 'linux',
    RepoTags: [
      'test:0.15',
      'test:latest',
    ],
    Size: 267464419,
    VirtualSize: 267464419,

    history: createSpy()
  };
}
開發者ID:Mercateo,項目名稱:dwatch,代碼行數:31,代碼來源:DockerFacade.ts

示例3: it

  it('can have multiple subscribers', () => {

    let pushToObservable: Function = () => {}
    let activations = 0
    let deactivationFunction = expect.createSpy<Function0<void>>()
    const obs = Observable<number>(add => {
      pushToObservable = add
      activations++
      return deactivationFunction
    })

    const subValues: {}[] = []
    const unsub1 = obs.subscribe(x => subValues.push({ 1: x }))
    const unsub2 = obs.subscribe(x => subValues.push({ 2: x }))

    expect(activations).toBe(1)
    expect(deactivationFunction.calls.length).toBe(0)
    expect(subValues).toEqual([])

    pushToObservable(10)
    expect(subValues).toEqual([{ 1: 10 }, { 2: 10 }])
    pushToObservable(20)
    expect(subValues).toEqual([{ 1: 10 }, { 2: 10 }, { 1: 20 }, { 2: 20 }])

    unsub1()
    expect(deactivationFunction.calls.length).toBe(0)
    unsub2()
    expect(deactivationFunction.calls.length).toBe(1)
    expect(activations).toBe(1)

    obs.subscribe(x => x)
    obs.subscribe(x => x)
    expect(activations).toBe(2)
  })
開發者ID:AlexGalays,項目名稱:kaiju,代碼行數:34,代碼來源:observable.ts

示例4: getContainerResponseMock

export function getContainerResponseMock (): any {
  return {
    Id: 'myId',
    Name: '/myContainer',
    Created: new Date(),
    Config: {
      WorkingDir: 'there',
      Image: 'myImage',
      Env: [ 'myEnv' ],
      Cmd: [ 'go-for-it' ]
    },
    State: {
      Running: true,
      FinishedAt: new Date(),
      StartedAt: new Date(),
      ExitCode: 0,
      Status: 'running'
    },
    NetworkSettings: {
      Ports: {
        '3000/tcp': null,
        '8000/udp': [
          {
            HostPort: '8080',
            HostIp: '1.3.3.7'
          }
        ]
      }
    },
    Node: {
      Addr: 'myAddr',
      Cpus: 5,
      id: 'nodeId',
      memoryLimit: 200,
      name: 'nodeName'
    },

    stop: createSpy(),
    start: createSpy(),
    pause: createSpy(),
    unpause: createSpy(),
    stats: createSpy(),
    top: createSpy()
  }
}
開發者ID:Webysther,項目名稱:dwatch,代碼行數:45,代碼來源:DockerFacade.ts

示例5: SumoLogger

import * as SumoLogger from 'sumo-logger';
import * as expect from 'expect';

const onErrorSpy = expect.createSpy();
const onSuccessSpy = expect.createSpy();

const logger = new SumoLogger({
    endpoint: 'http://example.com/',
    onSuccess() {
        console.log('success');
    },
    onError: onErrorSpy,
});

expect(logger.flushLogs).toExist();
expect(logger.log).toExist();

logger.log('message');
logger.log({ json: 'object' });

expect(onErrorSpy).toHaveBeenCalled();
expect(onErrorSpy.calls.length).toBe(2);
expect(onSuccessSpy).toNotHaveBeenCalled();
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:23,代碼來源:sumo-logger-tests.ts


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