Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Qaiser Abbas
authored and
Qaiser Abbas
committed
May 14, 2018
1 parent
925920c
commit 11435b4
Showing
5 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
import { BookStore } from '../index' | ||
import api from '../mock-api/api' | ||
|
||
it('bookstore fetches data', async () => { | ||
const store = BookStore.create({ books: [] }, { api }) | ||
let store = null | ||
|
||
beforeEach(async () => { | ||
store = BookStore.create({ books: [] }, { api }) | ||
await store.loadBooks() | ||
}) | ||
|
||
it('Bookstore fetches data', () => { | ||
expect(store.books.length).toBe(10) | ||
}) | ||
|
||
it(`Bookstore filter is set when setGenre() is called with a valid filter value`, async () => { | ||
store.setGenre('Nonfiction') | ||
expect(store.filter).toBe('Nonfiction') | ||
}) | ||
|
||
it(`Bookstore filter is NOT set when setGenre() is called with an invalid filter value`, async () => { | ||
expect(() => store.setGenre('Adventure')).toThrow() | ||
}) | ||
|
||
it(`Books are sorted by title`, async () => { | ||
const books = store.sortedBooks | ||
expect(books[0].title).toBe('By The Book') | ||
expect(books[1].title).toBe('Jane Eyre') | ||
}) | ||
|
||
it(`Books are sorted by title`, async () => { | ||
store.setGenre('Nonfiction') | ||
const books = store.sortedBooks | ||
expect(books.length).toBe(7) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters