本文整理匯總了TypeScript中Sinon.SinonStub.onFirstCall方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript SinonStub.onFirstCall方法的具體用法?TypeScript SinonStub.onFirstCall怎麽用?TypeScript SinonStub.onFirstCall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sinon.SinonStub
的用法示例。
在下文中一共展示了SinonStub.onFirstCall方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: beforeEach
beforeEach() {
spawnOnStub = stub();
const spawnOnResponse = {
on: spawnOnStub
};
spawnOnStub.returns(spawnOnResponse);
spawnStub = stub(cs, 'spawn').returns(spawnOnResponse);
},
afterEach() {
spawnStub.restore();
},
tests: {
async 'Should call spawn to run an npm process'() {
spawnOnStub.onFirstCall().callsArg(1);
await npmInstall.default();
assert.isTrue(spawnStub.calledOnce);
},
async 'Should reject with an error when spawn throws an error'() {
const errorMessage = 'test error message';
spawnOnStub.onSecondCall().callsArgWith(1, new Error(errorMessage));
try {
await npmInstall.default();
assert.fail(null, null, 'Should not get here');
} catch (error) {
assert.equal(errorMessage, error.message);
}
},
async 'Should install dependencies'() {
spawnOnStub.onFirstCall().callsArg(1);
示例2: beforeEach
beforeEach(() => {
getByFilterStub = s.stub(inst, 'getByFilter');
getByFilterStub.onFirstCall().callsFake(() => firstPeers);
getByFilterStub.onSecondCall().callsFake(() => secondPeers);
});
示例3: registerSuite
registerSuite({
name: 'loadCommands',
'beforeEach'() {
consoleStub = stub(console, 'error');
commandWrapper1 = getCommandWrapper('command1');
commandWrapper2 = getCommandWrapper('command2');
yargsStub = getYargsStub();
loadStub = stub();
goodConfig = config();
},
'afterEach'() {
consoleStub.restore();
},
'successful enumeration': {
'beforeEach'() {
loadStub.onFirstCall().returns(commandWrapper1);
loadStub.onSecondCall().returns(commandWrapper2);
},
async 'Should successfully enumerate installed commands'() {
const installedPaths = await enumInstalledCommands(goodConfig);
assert.equal(installedPaths.length, 2);
},
async 'Should successfully enumerate builtin commands'() {
const builtInPaths = await enumBuiltInCommands(goodConfig);
assert.equal(builtInPaths.length, 2); // includes invalid commands
}
},
'unsuccessful enumeration': {
async 'Should fail to find installed commands that dont exist'() {
goodConfig.searchPrefixes = [ 'bad-prefix' ];
const badPrefixPaths = await enumInstalledCommands(goodConfig);