bookish-react-2nd
bookish-react-2nd copied to clipboard
Found an issue early on in the book, chapter 5, with the order of books being inverted when running Cypress tests.
So I thought I would mention it here and maybe you or someone else could provide some insight. I was working through the code in your book and when I came to the part where you start to use Axios to delete and rebuild the JSON server database (page 72) I noticed that it would always invert the order and the tests would fail. The code in question is this:
beforeEach(() => {
const books = [
{
id: 1,
title: 'Refactoring',
},
{
id: 2,
title: 'Domain-driven design',
},
];
return books.map(item =>
axios.post('http://localhost:8080/books', item, {
headers: {
'Content-Type': 'application/json',
},
}),
);
});
Whenever I ran the code the test would fail with the following message:
Shows a book list:
Timed out retrying after 4000ms
+ expected - actual
-[ 'Domain-driven design', 'Refactoring' ]
+[ 'Refactoring', 'Domain-driven design' ]
So I started to watch db.json as the tests ran, and it would start out empty (as it would be cleared at the end of each test) then it would be populated by the books array in the right order, and then straight away it would invert the list. Then of course the test would fail.
This was driving me mad as I tried everything under the sun to try and understand what might be flipping the order and causing the tests to fail. I have even completely copy and pasted your spec.js code in (from the same stage in the book) and that is behaving the same way. The only way to make the test pass is to enter the books in reverse order:
const books = [
{
id: 2,
title: 'Domain-driven design',
},
{
id: 1,
title: 'Refactoring',
}
];
I have noticed that if I try and run it with 3 books, it starts out right (1 - 2 - 3), then book 2 goes to the top (2 - 1 - 3) and then finally 3 goes to the top (3 - 2 - 1). I feel it is something to do with the map function that posts the books but I can be sure.
Is this something you have encountered before and are you able to point out to me what is going on? I don't want to get too much further into the book if its failing at this early stage...
Thanks....