Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
'working' async version
Browse files Browse the repository at this point in the history
Issue is with nock('https://min-api.cryptocompare.com/') : isn't working
because nock expects port 443 for a scope match and that's not how
cryptocompare is working.

Drilling down.
  • Loading branch information
inkredabull committed Apr 19, 2018
1 parent 2306cce commit 33e2488
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/components/__tests__/listing-card_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ const peggedPrices = { USD: 546.61, EUR: 441.53 }
describe('<ListingCard />', () => {

beforeEach(function() {
nock('http://min-api.cryptocompare.com').get('/data/price?fsym=ETH&tsyms=USD').reply(200, { USD: 546.61 });
});

it('calculates retrieveConversion', () => {
it('calculates retrieveConversion', async () => {

nock('https://min-api.cryptocompare.com/')
.persist()
.get('/data/price?fsym=ETH&tsyms=USD')
.reply(200, { USD: 546.61 });

const wrapper = shallow(<ListingCard listingId="1" price={listingPrice} />);
const instance = wrapper.instance();

expect(instance.props.price).to.equal(listingPrice);
//await expect(instance().retrieveConversion()).to.eventually.be.fulfilled();
const promise = Promise.resolve(instance.retrieveConversion());
promise.then(() => {
expect(instance.props.approxPrice).to.equal(peggedPrices['USD']);
//instance.retrieveConversion().then(data => {
//expect(data).toEqual('Mark'));
expect(instance.props.approxPrice).to.equal(peggedPrices['USD']);
});

await instance.retrieveConversion();

expect(instance.state.approxPrice).to.equal(peggedPrices['USD']);
});
});
13 changes: 6 additions & 7 deletions src/components/listing-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ class ListingCard extends Component {

retrieveConversion(currencyCode){
const desiredCurrencyCode = currencyCode ? currencyCode : this.state.currencyCode
cc.price(targetCurrencyCode, [desiredCurrencyCode])
.then(prices => {
//console.log(prices[desiredCurrencyCode])
this.setState({ approxPrice: prices[desiredCurrencyCode] });
//this.setState({ currencyCode: desiredCurrencyCode });
})
.catch(console.error)
return new Promise((resolve, reject) => {
cc.price(targetCurrencyCode, [desiredCurrencyCode]).then(prices => {
resolve(this.setState({ approxPrice: prices[desiredCurrencyCode] }));
})
.catch(console.error)
});
}

render() {
Expand Down

0 comments on commit 33e2488

Please sign in to comment.