Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'sinon-test' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
/* @flow */
import assert from 'assert';
import sinon from 'sinon';
import sinonTestFactory from 'sinon-test';
const sinonTest = sinonTestFactory(sinon);
import {Machine} from '../src/index.js';
import {SimpleMachine} from '../src/simple-machine';
[Machine, SimpleMachine].forEach(Ctor => {
describe(Ctor.name, function() {
it('works with basic program', function() {
const output = [];
const mac = new Ctor({
code: '+.++.-.',
write: output
});
assert.strictEqual(mac.complete, false);
const cycles = mac.run();
assert.strictEqual(mac.complete, true);
assert.strictEqual(typeof cycles, 'number');
import Response from '../src/response.js';
import Validator from '../src/validator.js';
import Emitter from '../src/emitter.js';
import Config from '../src/config.js';
import fs from 'fs';
import chai, {
expect
} from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import sinonTest from 'sinon-test';
const test = sinonTest(sinon);
chai.use(sinonChai);
describe('Response', () => {
let validator;
let emitter;
let response;
beforeEach(() => {
validator = sinon.createStubInstance(Validator);
emitter = sinon.createStubInstance(Emitter);
response = new Response(validator, emitter);
});
it('should export a Response object', () => {
import ecurve from 'ecurve'
import sinon from 'sinon'
import sinonTestFactory from 'sinon-test'
import BigInteger from 'bigi'
import ECPair from '../../lib/crypto/ecpair'
import ecdsa from '../../lib/crypto/ecdsa'
import configManager from '../../lib/managers/config'
import fixtures from './fixtures/ecpair.json'
import { NETWORKS, NETWORKS_LIST } from '../utils/network-list'
const curve = ecdsa.__curve
const sinonTest = sinonTestFactory(sinon)
beforeEach(() => configManager.setConfig(NETWORKS.mainnet))
describe('ECPair', () => {
describe('constructor', () => {
it('defaults to compressed', () => {
const keyPair = new ECPair(BigInteger.ONE)
expect(keyPair.compressed).toBeTruthy()
})
it('supports the uncompressed option', () => {
const keyPair = new ECPair(BigInteger.ONE, null, {
compressed: false
})
import sinon from 'sinon'
import sinonTestFactory from 'sinon-test'
import BigInteger from 'bigi'
import ecdsa from '../../lib/crypto/ecdsa'
import bcrypto from '../../lib/crypto'
import ECSignature from '../../lib/crypto/ecsignature'
import fixtures from './fixtures/ecdsa.json'
const curve = ecdsa.__curve
const sinonTest = sinonTestFactory(sinon)
describe('ecdsa', () => {
describe('deterministicGenerateK', () => {
function checkSig () {
return true
}
fixtures.valid.ecdsa.forEach((f) => {
it(`for "${f.message}"`, () => {
const x = BigInteger.fromHex(f.d).toBuffer(32)
const h1 = bcrypto.sha256(f.message)
const k = ecdsa.deterministicGenerateK(h1, x, checkSig)
expect(k.toHex()).toBe(f.k)
})
})
import Client from '../src/client.js';
import Config from '../src/config.js';
import Request from '../src/request.js';
import Response from '../src/response.js';
import Account from 'nexmo/lib/Account';
import App from 'nexmo/lib/App';
import Message from 'nexmo/lib/Message';
import Number from 'nexmo/lib/Number';
import NumberInsight from 'nexmo/lib/NumberInsight';
import chai, { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import sinonTest from 'sinon-test';
const test = sinonTest(sinon);
chai.use(sinonChai);
describe('Request', () => {
it('should export a Request object', () => {
expect(Request).to.not.be.null;
expect(Request.name).to.equal('Request');
});
describe('with an instance', () => {
let client;
let config;
let nexmo;
let request;
let response;
import chai from 'chai';
import sinonTest from 'sinon-test';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import chaiEnzyme from 'chai-enzyme';
import { _init } from '../src/listener';
import { ops } from './mocks';
sinon.test = sinonTest.configureTest(sinon);
chai.should();
chai.use(sinonChai);
chai.use(chaiEnzyme());
_init(ops);
import assert from 'assert'
import sinon from 'sinon'
import sinonTestFactory from 'sinon-test'
import BigInteger from 'bigi'
import configManager from '../../lib/managers/config'
import ecdsa from '../../lib/crypto/ecdsa'
import ECPair from '../../lib/crypto/ecpair'
import HDNode from '../../lib/crypto/hdnode'
import { NETWORKS, NETWORKS_LIST } from '../utils/network-list'
import fixtures from './fixtures/hdnode.json'
const sinonTest = sinonTestFactory(sinon)
beforeEach(() => configManager.setConfig(NETWORKS.mainnet))
let validAll = []
fixtures.valid.forEach((f) => {
function addNetwork (n) {
n.network = f.network
return n
}
validAll = validAll.concat(addNetwork(f.master), f.children.map(addNetwork))
})
describe('HDNode', () => {
describe('Constructor', () => {
let keyPair
var path = require("path")
var should = require("should")
var sinon = require("sinon")
var sinonTest = require("sinon-test")
sinon.test = sinonTest.configureTest(sinon)
sinon.testCase = sinonTest.configureTestCase(sinon)
var api = require(__dirname + "/../../dadi/lib/api")
var Server = require(__dirname + "/../help").Server
var cache = require(__dirname + "/../../dadi/lib/cache")
var datasource = require(__dirname + "/../../dadi/lib/datasource")
var page = require(__dirname + "/../../dadi/lib/page")
var TestHelper = require(__dirname + "/../help")()
var config = require(path.resolve(path.join(__dirname, "/../../config")))
describe("Cache", function(done) {
beforeEach(function(done) {
TestHelper.resetConfig().then(() => {
done()
})
})
var path = require("path")
var should = require("should")
var sinon = require("sinon")
var sinonTest = require("sinon-test")
sinon.test = sinonTest.configureTest(sinon)
sinon.testCase = sinonTest.configureTestCase(sinon)
var api = require(__dirname + "/../../dadi/lib/api")
var Server = require(__dirname + "/../help").Server
var cache = require(__dirname + "/../../dadi/lib/cache")
var datasource = require(__dirname + "/../../dadi/lib/datasource")
var page = require(__dirname + "/../../dadi/lib/page")
var TestHelper = require(__dirname + "/../help")()
var config = require(path.resolve(path.join(__dirname, "/../../config")))
describe("Cache", function(done) {
beforeEach(function(done) {
TestHelper.resetConfig().then(() => {
done()
})
})