import React from 'react';
import CrudApi from '../api/CrudApi';
import nock from 'nock';
describe('CrudList Component', () => {
it('should have users', () => {
afterEach(() => {
nock.cleanAll()
})
CrudApi.getAll().then(
data => {expect(data).toHaveLength(9) // this failed
console.log(data.length) // 10}
)
});
});
This is my test case, it's supposed to fail because getAll
returns an array with 10 elements. In my console I'm seeing that the test passed, why is that?
The test indicates its passing because it is not waiting for the promise to resolve - you need to return the promise in the it
function:
it('should have users', () => {
afterEach(() => {
nock.cleanAll()
})
return CrudApi.getAll().then(
data => {expect(data).toHaveLength(9) // this failed
console.log(data.length) // 10}
)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With