Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const testMain = async ({ userFunc, exitCode }) => {
// Mock process.exit() to check exit code and prevent process exit
const processMock = sinon.mock(process);
const exitExpectation = processMock
.expects('exit')
.withExactArgs(exitCode)
.once()
.returns();
let error = null;
try {
await Promise.resolve()
.then(() => {
return new Promise((resolve, reject) => {
// Invoke main() function, the promise resolves after the user function is run
Apify.main(() => {
try {
// Wait for all tasks in Node.js event loop to finish
it('does nothing when the event key is not a space or enter button', function() {
const bodyEventsHandler = bodyEventsHandlerStamp({body : document.body});
const bodyEventsHandlerMock = sinon.mock(bodyEventsHandler);
const target = document.createElement('input');
const targetMock = sinon.mock(target);
const testHandler = e => { bodyEventsHandler.bodyKeyUpHandler(e); };
document.body.appendChild(target);
document.body.addEventListener(bodyEventsHandler.getKeyUpEventName(), testHandler);
bodyEventsHandlerMock.expects('elementIsCustomRadioOrCheckboxWidget').never();
targetMock.expects('click').never();
const keyUpEvent = new KeyboardEvent(bodyEventsHandler.getKeyUpEventName(), { bubbles: true, 'key': 'tab' });
target.dispatchEvent(keyUpEvent);
bodyEventsHandlerMock.verify();
targetMock.verify();
it('replays request on popstate if it had uiCache disabled', () => {
const naja = mockNaja({
historyHandler: HistoryHandler,
});
naja.initialize();
const mock = sinon.mock(naja);
mock.expects('makeRequest').withExactArgs(
'GET',
'/HistoryHandler/popStateWithoutCache',
null,
{
history: false,
historyUiCache: false,
},
).once();
window.dispatchEvent(createPopStateEvent({
href: '/HistoryHandler/popStateWithoutCache',
ui: false,
}));
cleanPopstateListener(naja.historyHandler);
it('returns true', function () {
let $checkbox = $('<input checked="checked" id="test1" name="test" type="checkbox">');
let $checkboxContainer = $('<div data-fv-min-selected="1" data-fv-group-container="test"></div>');
let $checkboxMock = sinon.mock($checkbox);
let $checkboxContainerMock = sinon.mock($checkboxContainer);
checkboxRulesSetMock.expects('getAttributeOwner').once()
.withArgs($checkbox).returns($checkboxContainer);
$checkboxContainerMock.expects('attr').once().withArgs('data-fv-min-selected').returns('1');
checkboxRulesSetMock.expects('getAllCheckboxesOrRadiosByName')
.once().withArgs($checkbox)
.returns($checkbox);
assert.isTrue(checkboxRulesSet.dataFvMinSelected($checkbox, 'data-fv-min-selected'));
$checkboxMock.verify();
$checkboxContainerMock.verify();
checkboxRulesSetMock.verify();
});
});
it('should throw an error when getEIP20Gateway returns undefined object', async () => {
mockGetContract = sinon.mock(
Contracts.getEIP20Gateway(web3, gatewayAddress),
);
setup();
mockedGatewayObject = undefined;
const errorMessage = `Could not load EIP20Gateway contract for: ${gatewayAddress}`;
assert.throws(() => {
new EIP20Gateway(web3, gatewayAddress);
}, errorMessage);
SpyAssert.assert(spyContract, 1, [[web3, gatewayAddress]]);
tearDown();
});
it('should call dialog with the supplied arguments', function() {
const sessionId = 123;
const context = {};
const text = 'beef';
const mockSessions = sinon.mock(this.sessions);
mockSessions.expects('read')
.withArgs(sessionId)
.returns(Promise.resolve({}));
const mockDialog = sinon.mock(this.dialog);
mockDialog.expects('run')
.withArgs(sessionId, context, text)
.returns({});
return expect(this.bot.receive(sessionId, text))
.to.eventually.be.fulfilled
.then(() => {
return mockDialog.verify();
});
});
it('accepts local netteForms reference', () => {
sinon.spy(window.Nette, 'initForm');
const mock = sinon.mock(netteForms);
mock.expects('initForm').once();
mock.expects('validateForm').once().returns(false);
const form = document.createElement('form');
const element = document.createElement('input');
form.appendChild(element);
document.body.appendChild(form);
const naja = mockNaja({
formsHandler: FormsHandler,
snippetHandler: SnippetHandler,
});
naja.formsHandler.netteForms = netteForms;
naja.initialize();
assert.equal(window.Nette.initForm.callCount, 0);
beforeEach(() => {
deffered = $q.defer();
delegateApiMock.expects('vote').returns(deffered.promise);
dilaogServiceMock = sinon.mock(controller.dialog);
});
getSocket: (): any => ({ socket, socketMock: mock(socket) }),
connection,
beforeEach(function () {
mockComponent = sinon.mock(InnerComponent.prototype);
createDom();
});