本文整理匯總了TypeScript中Sinon.sandbox.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript sandbox.create方法的具體用法?TypeScript sandbox.create怎麽用?TypeScript sandbox.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sinon.sandbox
的用法示例。
在下文中一共展示了sandbox.create方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: beforeEach
beforeEach(function () {
// Program state gets messed up by repeatedly calling it - lets dump it every time
delete require.cache[require.resolve("commander")];
sandbox = sinon.sandbox.create();
});
示例2: beforeEach
beforeEach(() => {
sandbox = sinon.sandbox.create();
});
示例3: describe
describe("Pact", () => {
const fullOpts = {
consumer: "A",
provider: "B",
port: 1234,
host: "127.0.0.1",
ssl: false,
logLevel: "info",
spec: 2,
cors: false,
pactfileWriteMode: "overwrite",
} as PactOptionsComplete;
let mockServiceStub: sinon.SinonStub;
const sandbox = sinon.sandbox.create({
injectInto: null,
properties: ["spy", "stub", "mock"],
useFakeTimers: false,
useFakeServer: false,
});
beforeEach(() => {
mockServiceStub = sandbox.stub(new PactNodeMockService());
});
afterEach(() => {
sandbox.restore();
});
describe("#constructor", () => {
let Pact: any;
beforeEach(() => {
const imported = proxyquire("./pact", {
"@pact-foundation/pact-node": sinon.createStubInstance(PactNodeFactory),
});
Pact = imported.Pact;
});
it("throws Error when consumer not provided", () => {
expect(() => { new Pact({ consumer: "", provider: "provider" }); }).
to.throw(Error, "You must specify a Consumer for this pact.");
});
it("throws Error when provider not provided", () => {
expect(() => { new Pact({ consumer: "someconsumer", provider: "" }); }).
to.throw(Error, "You must specify a Provider for this pact.");
});
});
describe("#createOptionsWithDefault", () => {
const constructorOpts: PactOptions = {
consumer: "A",
provider: "B",
};
it("should merge options with sensible defaults", () => {
const opts = PactType.createOptionsWithDefaults(constructorOpts);
expect(opts.consumer).to.eq("A");
expect(opts.provider).to.eq("B");
expect(opts.cors).to.eq(false);
expect(opts.host).to.eq("127.0.0.1");
expect(opts.logLevel).to.eq("info");
expect(opts.spec).to.eq(2);
expect(opts.dir).not.to.be.empty;
expect(opts.log).not.to.be.empty;
expect(opts.pactfileWriteMode).to.eq("overwrite");
expect(opts.ssl).to.eq(false);
expect(opts.sslcert).to.eq(undefined);
expect(opts.sslkey).to.eq(undefined);
});
});
describe("#setup", () => {
const Pact = PactType;
describe("when server is not properly configured", () => {
describe("and pact-node is unable to start the server", () => {
it("should return a rejected promise", (done) => {
const startStub = sandbox.stub(PactServer.prototype, "start").throws("start");
const b = Object.create(Pact.prototype) as any as PactType;
b.opts = fullOpts;
b.server = { start: startStub };
expect(b.setup()).to.eventually.be.rejected.notify(done);
});
});
});
describe("when server is properly configured", () => {
it("should start the mock server in the background", (done) => {
const startStub = sandbox.stub(PactServer.prototype, "start");
const b = Object.create(Pact.prototype) as any as PactType;
b.opts = fullOpts;
b.server = { start: startStub };
expect(b.setup()).to.eventually.be.fulfilled.notify(done);
});
});
});
describe("#addInteraction", () => {
const Pact = PactType;
//.........這裏部分代碼省略.........
示例4: setup
setup(() => {
sandbox = sinon.sandbox.create();
});
示例5: getInjector
_self.Before({ tags: [tag] }, (scenario: any) => {
sandbox = sinon.sandbox.create();
injector = getInjector();
});
示例6: describe
describe( `directives/directives_utils`, () => {
const sandbox = sinon.sandbox.create();
afterEach( () => {
sandbox.restore();
} );
describe( `IS utils`, () => {
const cmp = new ComponentMetadata( {
selector: 'cmp',
template: `hello`
} );
const directive = new DirectiveMetadata( {
selector: '[attr-dir]'
} );
describe( `#isAttrDirective`, () => {
it( `should check if instance is Attribute Directive`, () => {
expect( isAttrDirective( directive ) ).to.equal( true );
expect( isAttrDirective( cmp ) ).to.not.equal( true );
} );
} );
describe( `#isComponentDirective`, () => {
it( `should check if instance is Component`, () => {
expect( isComponentDirective( directive ) ).to.equal( false );
expect( isComponentDirective( cmp ) ).to.equal( true );
} );
} );
} );
describe( `#_setupDestroyHandler`, () => {
class MyComponent {
ngOnDestroy() {}
}
let $scope;
let $element;
let ctrl: MyComponent;
let watchers;
let observers;
beforeEach( () => {
$scope = new $Scope();
$element = ElementFactory();
ctrl = new MyComponent();
watchers = [];
observers = [];
} );
it( `should properly setup cleanup on directive destroy`, () => {
sandbox.spy( ctrl, 'ngOnDestroy' );
sandbox.spy( $element, 'off' );
_setupDestroyHandler( $scope as any, $element as any, ctrl, true, watchers, observers );
$scope.$$events[ 0 ].cb();
expect( (ctrl.ngOnDestroy as Sinon.SinonSpy).called ).to.equal( true );
expect( ($element.off as Sinon.SinonSpy).called ).to.equal( true );
} );
} );
} );
示例7: beforeEach
beforeEach(() => {
options = {};
sandbox = sinon.sandbox.create();
sandbox.stub(TestSelectorFactory.instance(), 'create').returns(testSelector);
sandbox.stub(TestSelectorFactory.instance(), 'knownNames').returns(['awesomeFramework', 'overrideTestSelector']);
});
示例8: describe
describe('keyed items', () => {
let container: HTMLElement;
const sandbox = Sinon.sandbox.create();
const mutationObserverConfig = {
childList: true,
subtree: true,
};
beforeEach(() => {
container = document.createElement('div');
document.body.appendChild(container);
});
afterEach(() => {
sandbox.restore();
document.body.removeChild(container);
});
/**
* @param container
*/
function createMutationObserver(container: Element): MutationObserver {
const mo = new MutationObserver(() => {});
mo.observe(container, mutationObserverConfig);
return mo;
}
/**
* @param keys
*/
function render(keys: number[]) {
keys.forEach((key) => {
elementOpen('div', key);
elementClose('div');
});
}
it('should cause no mutations when the items stay the same', () => {
patch(container, () => render([1, 2, 3]));
const mo = createMutationObserver(container);
patch(container, () => render([1, 2, 3]));
const records = mo.takeRecords();
expect(records).to.be.empty;
});
it('causes only one mutation when adding a new item', () => {
patch(container, () => render([1, 2, 3]));
const mo = createMutationObserver(container);
patch(container, () => render([0, 1, 2, 3]));
const records = mo.takeRecords();
expect(records).to.have.length(1);
});
it('cause a removal and addition when moving forwards', () => {
patch(container, () => render([1, 2, 3]));
const mo = createMutationObserver(container);
patch(container, () => render([3, 1, 2]));
const records = mo.takeRecords();
expect(records).to.have.length(2);
expect(records[0].addedNodes).to.have.length(0);
expect(records[0].removedNodes).to.have.length(1);
expect(records[1].addedNodes).to.have.length(1);
expect(records[1].removedNodes).to.have.length(0);
});
it('causes mutations for each item when removing from the start', () => {
patch(container, () => render([1, 2, 3, 4]));
const mo = createMutationObserver(container);
patch(container, () => render([2, 3, 4]));
const records = mo.takeRecords();
// 7 Mutations: two for each of the nodes moving forward and one for the
// removal.
expect(records).to.have.length(7);
});
});
示例9: beforeEach
beforeEach(function () {
// Picks up lint on re-runs - dump it every time
delete require.cache[require.resolve("commander")];
sandbox = sinon.sandbox.create();
sandbox.stub(process, "exit", function () {}); // Ignore exit()
});
示例10: describe
describe('issueNewId', () => {
let sandbox = sinon.sandbox.create();
let saveAsStub;
beforeEach(fakeAsync(() => {
mockModal.open.reset();
saveAsStub = sandbox.stub(fileSaver, 'saveAs');
}));
afterEach(() => {
sandbox.restore();
});
it('should show the new id', fakeAsync(inject([AlertService], (alertService: AlertService) => {
mockModal.open.onFirstCall().returns({
componentInstance: {},
result: Promise.resolve({userID: 'fred', userSecret: 'mySecret'})
});
mockModal.open.onSecondCall().returns({
componentInstance: {},
result: Promise.resolve({cardRef: 'cardOne', choice: 'add'})
});
let loadAllSpy = sinon.spy(component, 'loadAllIdentities');
let alertSpy = sinon.spy(alertService.successStatus$, 'next');
alertService.successStatus$.subscribe((message) => {
if (message) {
message.should.deep.equal({
title: 'ID Card added to wallet',
text: 'The ID card fred was successfully added to your wallet',
icon: '#icon-role_24'
});
}
});
fixture.detectChanges();
tick();
let issuedIdElement = fixture.debugElement.query(By.css('.flex-container button.secondary'));
issuedIdElement.triggerEventHandler('click', null);
tick();
alertSpy.should.have.been.called;
loadAllSpy.should.have.been.called;
})));
it('should export the new id', fakeAsync(() => {
// TODO: make this work with the real toArchive - can't get the promise to resolve properly
let expectedFile = new Blob(['card data'], {type: 'application/octet-stream'});
sinon.stub(cardOne, 'toArchive').resolves(expectedFile);
mockModal.open.onFirstCall().returns({
componentInstance: {},
result: Promise.resolve({userID: 'fred', userSecret: 'mySecret'})
});
mockModal.open.onSecondCall().returns({
componentInstance: {},
result: Promise.resolve({card: cardOne, choice: 'export'})
});
let loadAllSpy = sinon.spy(component, 'loadAllIdentities');
fixture.detectChanges();
tick();
let issuedIdElement = fixture.debugElement.query(By.css('.flex-container button.secondary'));
issuedIdElement.triggerEventHandler('click', null);
tick();
saveAsStub.should.have.been.calledWith(expectedFile, 'fred.card');
loadAllSpy.should.have.been.called;
}));
it('should add id to wallet when using the web profile', fakeAsync(inject([IdentityCardService, AlertService], (identityCardService: IdentityCardService, alertService: AlertService) => {
let myLoadParticipantsMock = sinon.stub(component, 'loadParticipants');
let myGetParticipantMock = sinon.stub(component, 'getParticipant');
myLoadParticipantsMock.returns(Promise.resolve());
myGetParticipantMock.returns(true);
let newCurrentIdCard = new IdCard({userName: 'penguinWeb', businessNetwork: 'igloo-network'}, {
'name': 'mycp',
'x-type': 'web'
});
identityCardService.addIdentityCard(newCurrentIdCard, 'webCard').then((cardRef) => {
currentCardRef = cardRef;
return identityCardService.setCurrentIdentityCard(cardRef);
});
tick();
mockModal.open.onFirstCall().returns({
componentInstance: {},
result: Promise.resolve({userID: 'snowMan', userSecret: 'mySecret'})
//.........這裏部分代碼省略.........