本文整理汇总了TypeScript中mockery.registerMock函数的典型用法代码示例。如果您正苦于以下问题:TypeScript registerMock函数的具体用法?TypeScript registerMock怎么用?TypeScript registerMock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了registerMock函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
});
let requestDeferred: IDeferred<any> = defer();
requestDeferred.resolve({ statusCode: 200 });
requestPromiseStub = sinon.stub().returns(requestDeferred.promise);
mockery.registerMock('request-promise', requestPromiseStub);
mockery.registerMock('node-sp-auth', {
getAuth: (data: any) => {
return Promise.resolve({});
}
});
sprequest = require('./../../src/core/SPRequest');
});
示例2: test
test('win', () => {
// Overwrite the statSync mock to say the x86 path doesn't exist
const statSync = (aPath: string) => {
if (aPath.indexOf('(x86)') >= 0) throw new Error('Not found');
};
mockery.registerMock('fs', { statSync });
const Utilities = getUtilities();
assert.equal(Utilities.getPlatform(), Utilities.Platform.Windows);
assert.equal(
Utilities.getBrowserPath(),
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe');
});
示例3: test
test('handles a relative path with a generated script url', () => {
const utilsMock = Mock.ofInstance(utils);
utilsMock.callBase = true;
mockery.registerMock('../utils', utilsMock.object);
testUtils.registerMockGetURL('../utils', GENERATED_SCRIPT_URL + '.map', FILEDATA, utilsMock);
setExpectedConstructorArgs(GENERATED_SCRIPT_URL, FILEDATA, PATHMAPPING);
return sourceMapFactory.getMapForGeneratedPath(GENERATED_SCRIPT_URL, 'script.js.map').then(sourceMap => {
assert(sourceMap);
utilsMock.verifyAll();
});
});
示例4: it
it("Speaks With Custom URL", function(done) {
process.argv = command("node bst-intend.js HelloIntent --url https://proxy.bespoken.tools");
mockery.registerMock("../lib/client/bst-virtual-alexa", {
BSTVirtualAlexa: function (url: string) {
this.url = url;
this.start = function() {};
assert.equal(this.url, "https://proxy.bespoken.tools");
done();
}
});
NodeUtil.load("../../bin/bst-intend.js");
});
示例5: it
it("Generates a launch request with Application ID", function(done) {
process.argv = command("node bst-launch.js --appId 1234567890");
mockery.registerMock("../lib/client/bst-virtual-alexa", {
BSTVirtualAlexa: function (skillURL: any, interactionModel: any, intentSchemaFile: any, sampleUtterancesFile: any, applicationID: string) {
assert.equal(applicationID, "1234567890");
this.start = function () {};
this.launched = function (callback: any) {};
done();
}
});
NodeUtil.load("../../bin/bst-launch.js");
});
示例6: it
it("Speaks With Application ID Succinct Syntax", function(done) {
process.argv = command("node bst-utter.js Hello -a 1234567890");
mockery.registerMock("../lib/client/bst-virtual-alexa", {
BSTVirtualAlexa: function (skillURL: any, interactionModel: any, intentSchemaFile: any, sampleUtterancesFile: any, applicationID: string) {
assert.equal(applicationID, "1234567890");
this.start = function () {};
this.spoken = function (utterance: string, callback: any) {};
done();
}
});
NodeUtil.load("../../bin/bst-utter.js");
});
示例7: it
it('gets correct local registries', () => {
let mockParser = {
GetRegistries: (npmrc: string) => [
'http://registry.com/npmRegistry/',
'http://example.pkgs.visualstudio.com/npmRegistry/',
'http://localTFSServer/npmRegistry/'
]
};
mockery.registerMock('./npmrcparser', mockParser);
let mockTask = {
getVariable: (v: string) => {
if (v === 'System.TeamFoundationCollectionUri') {
return 'http://example.visualstudio.com';
}
},
debug: (message: string) => {
// no-op
},
loc: (key: string) => {
// no-op
}
};
mockery.registerMock('vsts-task-lib/task', mockTask);
let npmutil = require('../npm/npmutil');
return npmutil.getLocalRegistries(['http://example.pkgs.visualstudio.com/', 'http://example.com'], '').then((registries: string[]) => {
assert.equal(registries.length, 1);
assert.equal(registries[0], 'http://example.pkgs.visualstudio.com/npmRegistry/');
mockTask.getVariable = () => 'http://localTFSServer/';
return npmutil.getLocalRegistries(['http://localTFSServer/', 'http://example.com'], '').then((registries: string[]) => {
assert.equal(registries.length, 1);
assert.equal(registries[0], 'http://localTFSServer/npmRegistry/');
});
});
});
示例8: it
it('fails if installing packages to the base environment fails', async function () {
mockery.registerMock('vsts-task-lib/task', mockTask);
const findConda = sinon.stub().returns('path-to-conda');
const prependCondaToPath = sinon.spy();
const installPackagesGlobally = sinon.stub().rejects(new Error('installPackagesGlobally'));
mockery.registerMock('./conda_internal', {
findConda,
prependCondaToPath,
installPackagesGlobally
});
const uut = reload('../conda');
const parameters = {
createCustomEnvironment: false,
packageSpecs: 'pytest',
updateConda: false
};
// Can't use `assert.throws` with an async function
// Node 10: use `assert.rejects`
let error: any | undefined;
try {
await uut.condaEnvironment(parameters, Platform.Linux);
} catch (e) {
error = e;
}
assert(error instanceof Error);
assert.strictEqual(error.message, 'installPackagesGlobally');
assert(findConda.calledOnceWithExactly(Platform.Linux));
assert(prependCondaToPath.calledOnceWithExactly('path-to-conda', Platform.Linux));
assert(installPackagesGlobally.calledOnceWithExactly('pytest', Platform.Linux, undefined));
});