Is testing possible with firebase firestore? I have been following testing tutorial and test that work for others are not working for me.
My component code Works in the client, so I'm very confused why I'm getting this error.
I have only found information regarding testing security rules in firebase, but nothing about firestore, does that mean that its the only thing that we can test?
this is the error that I get:
FIRESTORE (9.6.1) INTERNAL ASSERTION FAILED: Unexpected state
at fail (node_modules/@firebase/firestore/src/util/assert.ts:40:9)
at hardAssert (node_modules/@firebase/firestore/src/util/assert.ts:54:5)
at fromBytes (node_modules/@firebase/firestore/src/remote/serializer.ts:252:5)
at fromWatchChange (node_modules/@firebase/firestore/src/remote/serializer.ts:475:25)
at PersistentListenStream.onMessage (node_modules/@firebase/firestore/src/remote/persistent_stream.ts:642:25)
at node_modules/@firebase/firestore/src/remote/persistent_stream.ts:517:21
at node_modules/@firebase/firestore/src/remote/persistent_stream.ts:570:18
at node_modules/@firebase/firestore/src/util/async_queue_impl.ts:135:7
at node_modules/@firebase/firestore/src/util/async_queue_impl.ts:186:14
ā if the user is fetched, the name is shown
Unable to find an element with the text: /James/i. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
My component code:
function Hellopage() {
const [userData, setUserData] = useState();
const getData = async () => {
const docRef = doc(firestore, "users", "pW5CizOJOpXezr5lGGshDmKdVzZ2");
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
setUserData(docSnap.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
};
useEffect(() => {
getData();
}, []);
return (
<div>
<div>{userData?.name}</div>
</div>
);
}
export default Hellopage;
My Test :
test("if the user is fetched, the name is shown", async () => {
const result = render(<HelloPage />);
expect(await result.findByText(/James/i)).toBeInTheDocument();
});