UNPKG

@sk1ppi/js_nitter_scraper

Version:

![Made by](https://img.shields.io/badge/SK1PPI-8A2BE2) ![GitHub License](https://img.shields.io/github/license/sk1ppi/js_nitter_scraper) ![NPM Version](https://img.shields.io/npm/v/@sk1ppi/js_nitter_scraper)

33 lines (25 loc) 1.24 kB
const { getLatestTweetsByUsername } = require('./index') describe('getLatestTweetsByUsername', () => { it('throws an error if no username is provided', async () => { await expect(getLatestTweetsByUsername()).rejects.toThrow('Twitter username is required') }) it('returns an array of tweets', async () => { const tweets = await getLatestTweetsByUsername('elonmusk') expect(tweets).toBeInstanceOf(Array) }) it('returns an array of tweets with the correct properties', async () => { const properties = ['tweetLink', 'tweetPhotoURL', 'tweetFullName', 'tweetUsername', 'tweetDate', 'tweetMoment', 'tweetText', 'tweetTextHtml', 'tweetFullHtml', 'tweetId'] const tweets = await getLatestTweetsByUsername('elonmusk') const tweet = tweets[0] const tweetProperties = Object.keys(tweet) // attachments is optional const hasAttachments = tweetProperties.includes('tweetAttachments') expect(tweet).toBeInstanceOf(Object) properties.forEach(property => { expect(tweetProperties).toContain(property) }) if (hasAttachments) { expect(tweetProperties).toContain('tweetAttachments') } }) })