Test for Smokeball
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

  1. import { getArnieQuotes } from './get-arnie-quotes';
  2. const urls = [
  3. 'http://www.smokeballdev.com/arnie0',
  4. 'http://www.smokeballdev.com/arnie1',
  5. 'http://www.smokeballdev.com/arnie2',
  6. 'http://www.smokeballdev.com/arnie3',
  7. ];
  8. test('expect no throws', () => {
  9. expect.assertions(1);
  10. expect(async () => await getArnieQuotes(urls)).not.toThrow();
  11. });
  12. test('responses to be correct', async () => {
  13. expect.assertions(5);
  14. const results = await getArnieQuotes(urls);
  15. expect(results.length).toBe(4);
  16. expect(results[0]).toEqual({ 'Arnie Quote': 'Get to the chopper' });
  17. expect(results[1]).toEqual({ 'Arnie Quote': 'MY NAME IS NOT QUAID' });
  18. expect(results[2]).toEqual({ 'Arnie Quote': `What's wrong with Wolfie?` });
  19. expect(results[3]).toEqual({ 'FAILURE': 'Your request has been terminated' });
  20. });
  21. test('code to be executed in less than 400ms', async () => {
  22. expect.assertions(2);
  23. const startTime = process.hrtime();
  24. await getArnieQuotes(urls);
  25. const [ seconds, nanos ] = process.hrtime(startTime);
  26. expect(seconds).toBe(0);
  27. expect(nanos / 1000 / 1000).toBeLessThan(400);
  28. });