I am trying to run some unit tests in my NestAPI. My service.ts has this:
findAll(): Promise<Users[]> {
return prisma.users.findMany();
}
In my service.spec.ts:
const usersMany = [
{
username: 'user1',
name: 'User One',
password: '123',
email: 'user1@test.com',
tasks: [],
},
{
username: 'user2',
name: 'User Two',
password: '456',
email: 'user2@test.com',
tasks: [],
}
}
And after that, I have this test case for my FindAll()
describe('findAll', () => {
it('should return all users', async () => {
const usersAll = await service.findAll();
expect(usersAll).toEqual(usersMany);
});
});
However, when I run this test, I get the following error:
- Expected - 23
+ Received + 1
- Array [
- Object {
- "email": "user1@test.com",
- "name": "User One",
- "password": "123",
- "tasks": Array [],
- "username": "user1",
- },
- Object {
- "email": "user2@test.com",
- "name": "User Two",
- "password": "456",
- "tasks": Array [],
- "username": "user2",
- },
- ]
+ Array []
I'm new to writing unit tests, so would really appreciate some help here. Why is my test failing here?