|
| 1 | +import { fetchSearchResults } from './search'; |
| 2 | + |
| 3 | +describe('fetchSearchResults', () => { |
| 4 | + // Replace `xit` for `it` in each test |
| 5 | + xit('Returns a promise', () => { |
| 6 | + expect(fetchSearchResults()).toBeInstanceOf(Promise); |
| 7 | + }); |
| 8 | + |
| 9 | + xit('Returns an empty response if no query is given', done => { |
| 10 | + return fetchSearchResults().then(results => { |
| 11 | + expect(results).toEqual([]); |
| 12 | + done(); |
| 13 | + }); |
| 14 | + }); |
| 15 | + |
| 16 | + xit('Returns an empty response if query is ""', done => { |
| 17 | + return fetchSearchResults('').then(results => { |
| 18 | + expect(results).toEqual([]); |
| 19 | + done(); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + xit('Throws if query has not type `string`', () => { |
| 24 | + expect(() => { |
| 25 | + fetchSearchResults({}); |
| 26 | + }).toThrow(TypeError); |
| 27 | + |
| 28 | + expect(() => { |
| 29 | + fetchSearchResults([]); |
| 30 | + }).toThrow(TypeError); |
| 31 | + |
| 32 | + expect(() => { |
| 33 | + fetchSearchResults(NaN); |
| 34 | + }).toThrow(TypeError); |
| 35 | + |
| 36 | + expect(() => { |
| 37 | + fetchSearchResults(12345); |
| 38 | + }).toThrow(TypeError); |
| 39 | + |
| 40 | + expect(() => { |
| 41 | + fetchSearchResults(true); |
| 42 | + }).toThrow(TypeError); |
| 43 | + }); |
| 44 | + |
| 45 | + xit('Returns an array of products when a query is given', done => { |
| 46 | + const expected = [ |
| 47 | + { |
| 48 | + productUrl: |
| 49 | + 'https://www.tiqets.com/en/barcelona-c66342/sagrada-familia-fast-track-p918256', |
| 50 | + image: |
| 51 | + 'https://aws-tiqets-cdn.imgix.net/images/content/3ca6b020234e47448d46547ff3ac6b3f.jpg?auto=format&fit=crop&h=500&ixlib=python-1.1.2&q=70&w=500&s=04a6235ad28f4e3ce24d3db42d3dc3de', |
| 52 | + id: 918256, |
| 53 | + title: 'Sagrada Familia: Fast Track', |
| 54 | + price: 17.0, |
| 55 | + summary: |
| 56 | + "Make seeing the Sagrada Familia the first thing you do in Barcelona! The lines can be long, so join the many people who visited Barcelona's top attraction with our fast-track tickets and save yourself time and money.", |
| 57 | + }, |
| 58 | + ]; |
| 59 | + |
| 60 | + return fetchSearchResults('sagrada familia').then(results => { |
| 61 | + expect(results).toEqual(expected); |
| 62 | + done(); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments