Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('with error in the code, should return correct line number in error', () => {
code = '// Prepend\n error';
state = generateDefaultState(workspaceLocation, { editorPrepend: '// Prepend' });
runInContext(code, context, { scheduler: 'preemptive', originalMaxExecTime: 1000 }).then(
result => (context = (result as Finished).context)
);
const errors = context.errors.map((error: SourceError) => {
const newError = cloneDeep(error);
newError.location.start.line = newError.location.start.line - 1;
newError.location.end.line = newError.location.end.line - 1;
return newError;
});
return expectSaga(evalCode, code, context, execTime, workspaceLocation, actionType)
.withState(state)
.call(runInContext, code, context, {
scheduler: 'preemptive',
originalMaxExecTime: execTime
})
.put(actions.evalInterpreterError(errors, workspaceLocation))
.silentRun();
});
});
it('saga: saveSerializedClaimOffer', () => {
const claimHandle = 1
return expectSaga(
saveSerializedClaimOffer,
claimHandle,
pairwiseConnection.identifier,
uid
)
.provide([
[
matchers.call.fn(serializeClaimOffer, claimHandle),
serializedClaimOffer,
],
[
matchers.call.fn(getClaimOfferState, claimHandle),
claimOfferVcxInitialState,
],
])
.put(
it('check pin flow should work if correct pin is passed', () => {
const pin = '123456'
const salt = 'salt'
const expectedPinHash = 'expectedPinHash'
return expectSaga(checkPin, checkPinAction(pin))
.provide([
[matchers.call.fn(safeGet, IN_RECOVERY), null],
[call(getHydrationItem, SALT), salt],
[call(getHydrationItem, PIN_HASH), expectedPinHash],
[matchers.call.fn(pinHash, pin, salt), expectedPinHash],
])
.put(checkPinSuccess())
.run()
})
test('loads CURVES library correctly', () => {
const newExternalLibraryName = ExternalLibraryNames.CURVES;
const symbols = externalLibraries.get(newExternalLibraryName)!;
const library: Library = {
chapter,
external: {
name: newExternalLibraryName,
symbols
},
globals
};
return expectSaga(workspaceSaga)
.put(actions.endClearContext(library, workspaceLocation))
.dispatch({
type: actionTypes.BEGIN_CLEAR_CONTEXT,
payload: { library, workspaceLocation }
})
.silentRun()
.then(() => {
expect(loadLib).toHaveBeenCalledWith('CURVES');
expect(getReadyWebGLForCanvas).toHaveBeenCalledWith('curve');
globals.forEach(item => {
expect(window[item[0]]).toEqual(item[1]);
});
});
});
});
it("returns error on failed request", () => {
const error = new Error("Failed request");
expectSaga(requestStatementsSaga)
.provide([[matchers.call.fn(getStatements), throwError(error)]])
.put(actions.failed(error))
.withReducer(reducer)
.hasFinalState({
data: null,
lastError: error,
valid: false,
})
.run();
});
});
it("successfully requests node liveness statuses", () => {
expectSaga(requestLivenessSaga)
.provide([[matchers.call.fn(getLiveness), livenessResponse]])
.put(actions.received(livenessResponse))
.withReducer(reducer)
.hasFinalState({
data: livenessResponse,
lastError: null,
valid: true,
})
.run();
});