- Test the API
-
Create the file
src\projects\__tests__\projectAPI-test.js
. -
Add the following code to test the updating of a project.
import { MOCK_PROJECTS } from '../MockProjects'; import { projectAPI } from '../projectAPI'; describe('projectAPI', () => { test('should return records', () => { const response = new Response(undefined, { status: 200, statusText: 'OK', }); response.json = () => Promise.resolve(MOCK_PROJECTS); jest .spyOn(window, 'fetch') .mockImplementation(() => Promise.resolve(response)); return projectAPI .get() .then((data) => expect(data).toEqual(MOCK_PROJECTS)); }); });
-
Verify the test passes.
PASS src/projects/__tests__/projectAPI-test.js