Skip to content

Instantly share code, notes, and snippets.

@louisptremblay
Created January 20, 2017 20:12
Show Gist options
  • Save louisptremblay/dac2f742c7b74abce5209d38ff10f104 to your computer and use it in GitHub Desktop.
Save louisptremblay/dac2f742c7b74abce5209d38ff10f104 to your computer and use it in GitHub Desktop.
import { expect } from 'chai';
const proxyquire = require('proxyquire').noCallThru();
const requestsMock = { get: null };
const Tools = proxyquire('../Tools', {
'../../../utils/api/requests': requestsMock,
});
describe('Tools', () => {
describe('fileExists', () => {
it('should return true if the file exists', () => {
requestsMock.get = () => ({ status: 200, json: () => Promise.resolve('exists') });
const exists = Tools.fileExists('foobar.txt');
return exists.then(v => expect(v).to.be.true);
});
it('should return false if the file doesnt exist', () => {
requestsMock.get = () => ({ status: 400 });
const exists = Tools.fileExists('foobar.txt');
return exists.then(v => expect(v).to.be.false);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment