JSFiddle - React, Tailwind, and code Playground
by Ksenia Polyakova
JavaScript
const { assert } = require('chai');
const Serial = require('../SerialRequest');
const sinon = require('sinon');
const data = require('./testData.json');
class ss extends Serial {
constructor(fakeJs) {
super();
this.toJson = () => fakeJs;
}
};
const se = new ss(data);
global.fetch = () => {};
const urls = [
'https://jsonplaceholder.typicode.com/photos',
'https://jsonplaceholder.typicode.com/posts/2',
];
let testOne = null;
let resp = null;
let testTwo = null;
const ok = (res) => {
console.log('!!!');
testOne = true;
console.log(testOne);
resp = res;
};
const no = (err) => { testTwo = false; console.log(err); };
describe('SerialRequest', () => {
it('должен выполняться колбэк Ok', (done) => {
sinon.stub(global, 'fetch').returns(Promise.resolve());
se.get(urls[0], ok, no)
.get(urls[1], ok, no);
assert.equal(testOne, true);
setTimeout(() => { done(); }, 1000);
});
})