Skip to content

Instantly share code, notes, and snippets.

@jaybill
Created May 7, 2015 17:31
Show Gist options
  • Save jaybill/708053e1d875cba10d6b to your computer and use it in GitHub Desktop.
Save jaybill/708053e1d875cba10d6b to your computer and use it in GitHub Desktop.
'use strict';
export default class fakeAppDAO {
constructor() {
}
callServer(path, method = "GET", query = {}, data) {
var endpoint = path + "|" + method;
var returnData;
switch(endpoint){
case "/markets/9999|GET":
// change this to whatever you'd actually want to return here, i.e., something that looks more like market data
returnData = [
{id: 3, name: "foo"},
{id: 4, name: "bar"},
]
break;
}
return new Promise(
(resolve, reject) => {
resolve(returnData);
}
);
}
}
var rewire = require('rewire');
var rewireModule = require('../../test/helpers/rewire-module.js');
var dump = require('../../test/helpers/util.js').dump;
var React = require('react');
var fakeAppDao = require('../../test/helpers/fakeAppDAO.js')
describe("Market (DAO)", function() {
var Market = rewire("./Market.js");
var rw = {
AppDAO: fakeAppDAO
}
rewireModule(Market,rw);
it("returns multiple markets", function() {
var ready = false,
result;
runs( function()
{
Market
.fetchAll()
.then(
function onResponse( data )
{
result = data;
ready = true; // continue test runner
},
function onError( fault )
{
ready = true; // continue test runner
}
);
});
// Pause test runner until timeout or yourAsyncCall() responds
waitsFor( function()
{
return result;
});
// Run the code that checks the expectations…
runs( function()
{
expect( result.length ).toBeEqual( 2 );
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment