browser.spec.js (1660B)
1 "use strict"; 2 3 const searchYoutube = require('../../src'); 4 const assert = require('assert'); 5 6 const YOUTUBE_KEY = window.__env.YOUTUBE_KEY; 7 8 describe('Search The Youtube Api', function () { 9 "use strict"; 10 //key , options , cb 11 const options = { 12 q: 'nodejs', 13 part: 'snippet', 14 type: 'video' 15 }; 16 17 it('should Throw API Key is required! using callback', function (done) { 18 searchYoutube(null, null, (err, res) => { 19 assert.equal(err.message, 'API Key is required', 'did not throw API Key is required message') 20 done(); 21 }); 22 }); 23 24 25 it('should Throw API Key is required! using Promise', function (done) { 26 assert.throws(searchYoutube, /API Key is required/, 'did not throw API Key is required message'); 27 done(); 28 }); 29 30 it('should return a Response object using a callback', function (done) { 31 searchYoutube(YOUTUBE_KEY, options, function (err, result) { 32 //result.kind: 'youtube#searchListResponse' 33 if (err) done(err); 34 assert.deepEqual(result.kind, 'youtube#searchListResponse'); 35 done(); 36 }); 37 }); 38 39 it('should return a Response object using a Promise', function (done) { 40 41 searchYoutube(YOUTUBE_KEY, options) 42 .then(result => { 43 assert.deepEqual(result.kind, 'youtube#searchListResponse'); 44 done(); 45 }) 46 .catch(err => { 47 done(err) 48 }); 49 }); 50 });