Skip to content

Commit

Permalink
added testing and jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ZinxValkyria committed May 31, 2024
1 parent df1f926 commit 2455911
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 2 deletions.
42 changes: 42 additions & 0 deletions __tests__/test.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const request = require('supertest');
const app = require('./app');

describe('GET /', () => {
test('It should respond with status 200 and render index page', async () => {
const response = await request(app).get('/');
expect(response.status).toBe(200);
expect(response.text).toContain('index');
});
});

describe('GET /movies', () => {
test('It should respond with status 200 and render movies page', async () => {
const response = await request(app).get('/movies');
expect(response.status).toBe(200);
expect(response.text).toContain('movies');
});
});

// Add more tests for other routes...

describe('GET /api/character', () => {
test('It should respond with character data', async () => {
const response = await request(app).get('/api/character?character=Spider-Man');
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('id');
expect(response.body).toHaveProperty('name', 'Spider-Man');
// Add more assertions as needed...
});

test('It should handle errors gracefully', async () => {
// Mock the axios get method to simulate an error
jest.spyOn(require('axios'), 'get').mockRejectedValue(new Error('Axios error'));

const response = await request(app).get('/api/character?character=Spider-Man');
expect(response.status).toBe(500);
expect(response.body).toHaveProperty('error', 'Internal Server Error');
});
});

// Add more tests for other API endpoints...

119 changes: 118 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"devDependencies": {
"jest": "^29.7.0",
"mocha": "^10.4.0"
"mocha": "^10.4.0",
"supertest": "^7.0.0"
}
}

0 comments on commit 2455911

Please sign in to comment.