UNPKG

weiser-leaders-quotes

Version:

A package that returns a random quote from w(e)ise world leaders.

55 lines (43 loc) 1.75 kB
// index.test.js const WorldLeaderQuotes = require('./index'); describe('WorldLeaderQuotes', () => { let quoteGenerator; beforeEach(() => { quoteGenerator = new WorldLeaderQuotes(); }); describe('getRandomQuote', () => { test('should return a quote object with required properties', () => { const quote = quoteGenerator.getRandomQuote(); expect(quote).toHaveProperty('quote'); expect(quote).toHaveProperty('author'); expect(quote).toHaveProperty('country'); expect(quote).toHaveProperty('category'); }); test('should return different quotes on multiple calls', () => { // Due to randomness, this test might occasionally fail // We'll call it multiple times to reduce the probability const quotes = new Set(); for (let i = 0; i < 10; i++) { quotes.add(JSON.stringify(quoteGenerator.getRandomQuote())); } // With our small dataset, we expect at least 2 different quotes expect(quotes.size).toBeGreaterThan(1); }); }); describe('getQuoteByAuthor', () => { test('should return quotes by Gandhi when searching for "Gandhi"', () => { const quotes = quoteGenerator.getQuoteByAuthor('Gandhi'); expect(quotes).toHaveLength(1); expect(quotes[0].author).toBe('Mahatma Gandhi'); }); test('should be case insensitive', () => { const quotes = quoteGenerator.getQuoteByAuthor('gandhi'); expect(quotes).toHaveLength(1); expect(quotes[0].author).toBe('Mahatma Gandhi'); }); test('should return empty array for non-existent author', () => { const quotes = quoteGenerator.getQuoteByAuthor('Non Existent'); expect(quotes).toHaveLength(0); }); }); });