本文整理汇总了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);
}
示例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()
};
}
示例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)
})
示例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()
}
}
示例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();