本文整理匯總了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();