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


TypeScript SinonStub.onFirstCall方法代碼示例

本文整理匯總了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);
開發者ID:dojo,項目名稱:cli,代碼行數:31,代碼來源:npmInstall.ts

示例2: beforeEach

 beforeEach(() => {
   getByFilterStub = s.stub(inst, 'getByFilter');
   getByFilterStub.onFirstCall().callsFake(() => firstPeers);
   getByFilterStub.onSecondCall().callsFake(() => secondPeers);
 });
開發者ID:RiseVision,項目名稱:rise-node,代碼行數:5,代碼來源:peers.spec.ts

示例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);
開發者ID:dylans,項目名稱:cli,代碼行數:31,代碼來源:loadCommands.ts


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