🌍 ExpressJS · subject
ExpressJS Testing and Debugging in ExpressJS Syllabus
Every chapter and topic of Testing and Debugging in ExpressJS examined in ExpressJS — 3 chapters, 7 topics, plus 50 flashcards written against it.
Testing and Debugging in ExpressJS syllabus — full chapter and topic list
Expand any chapter to see its topics and sub-topics. This is the whole examinable outline for Testing and Debugging in ExpressJS in ExpressJS, not a summary of it.
-
Unit Testing
3 topics- Using Mocha and Chai
- Testing Middleware
- Testing Routes
-
Integration Testing
2 topics- Using Supertest
- Mocking Dependencies
-
Debugging Techniques
2 topics- Using Debug Module
- Using Node.js Inspector
Testing and Debugging in ExpressJS flashcards for ExpressJS
18 of 50 cards from the Testing and Debugging in ExpressJS deck — real questions with worked answers.
What are Mocha and Chai, and what role does each play in testing an ExpressJS application?
Mocha is a JavaScript test framework that runs test suites and provides the structure (describe/it blocks, hooks, async support). Chai is a standalone assertion library used inside those tests to express expectations. Mocha runs the tests; Chai checks that values are correct.
Which Mocha functions define a test suite versus an individual test case?
describe() defines a suite (a grouping of related tests), and it() defines an individual test case. Suites can be nested; each it() contains one or more assertions.
List the four Mocha lifecycle hooks and when each runs.
before() runs once before all tests in a block; after() runs once after all tests; beforeEach() runs before every individual test; afterEach() runs after every individual test.
What are Chai's three assertion styles?
assert (assert.equal(a,b)), expect (expect(a).to.equal(b)), and should (a.should.equal(b)). expect and should are BDD-style chainable; assert is TDD-style.
In Chai's expect style, how do you assert that a value strictly equals 200 versus is deeply equal to an object?
Use expect(res.status).to.equal(200) for strict (===) equality, and expect(obj).to.deep.equal({a:1}) for deep structural equality of objects/arrays.
How do you handle asynchronous code in a Mocha test that returns a Promise?
Return the Promise from the test callback (Mocha waits for it to resolve/reject), or use an async function and await the Promise. Alternatively call the done callback for callback-style async.
What is the purpose of the done callback in a Mocha test, and what causes a timeout error?
done signals completion of an asynchronous test. Mocha waits until done() is called; if it is never called (or the async op exceeds the default 2000 ms timeout), Mocha fails the test with a timeout error.
What command-line flag sets a custom timeout in Mocha, and what is the default timeout?
The default timeout is 2000 ms. Override it with --timeout <ms> on the CLI, or per-test with this.timeout(ms) inside a non-arrow test function.
Why should you avoid arrow functions when you need this.timeout() or this.skip() in Mocha tests?
Arrow functions do not bind their own this, so Mocha's context (with .timeout(), .skip(), .retries()) is unavailable. Use regular function() expressions to access the Mocha context.
What is Supertest and what problem does it solve when testing Express apps?
Supertest is a library for high-level HTTP assertion testing. It wraps your Express app, spins up an ephemeral server, sends real HTTP requests, and lets you assert on responses without manually starting/stopping a server or hardcoding ports.
Write a minimal Supertest request that GETs '/users' and asserts a 200 status.
request(app).get('/users').expect(200); where request is require('supertest'). Return this from the test or await it so Mocha waits for completion.
In Supertest, how do you send a JSON POST body and set a request header?
request(app).post('/users').set('Content-Type','application/json').send({ name: 'Ann' }).expect(201). .send() sets the body and .set() sets headers.
What must you export from your Express module so Supertest can test it without the server already listening?
Export the app instance (module.exports = app) rather than the result of app.listen(). Supertest binds to the app and manages an ephemeral port itself.
How do you chain multiple .expect() assertions in Supertest, and what are the valid argument forms?
You can chain multiple .expect() calls. Forms: expect(status), expect(status, body), expect(field, value) for a header, expect(body) for the response body, or expect(fn) with a custom assertion function that throws on failure.
How do you access the full response object at the end of a Supertest chain to run custom Chai assertions?
Use .then(res => { ... }) or await the chain: const res = await request(app).get('/'); then assert on res.status, res.body, res.headers with Chai.
When testing an Express route that returns JSON, how do you assert both the status code and a property in the response body using Supertest and Chai?
const res = await request(app).get('/api/item/1'); expect(res.status).to.equal(200); expect(res.body).to.have.property('name','Widget'). res.body is the parsed JSON.
What is Express middleware, and what three arguments does a standard (non-error) middleware function receive?
Middleware is a function that runs during the request-response cycle with access to req, res, and next. It receives (req, res, next); calling next() passes control to the next middleware.
How many arguments does Express error-handling middleware take, and in what order?
Four: (err, req, res, next). Express identifies error-handling middleware by its four-parameter signature; err is the error passed via next(err).
Planning Testing and Debugging in ExpressJS for ExpressJS
Testing and Debugging in ExpressJS is about 13% of the ExpressJS syllabus by topic count — 7 of 54 topics, spread over 3 chapters. At roughly 45 minutes per topic plus 12 minutes per sub-topic, a first pass runs to about 5 hours.
The heaviest chapters are Unit Testing (3 topics), Integration Testing (2 topics), Debugging Techniques (2 topics) . Front-load those while your energy is high; the short chapters are better revision filler later.
Work top-down: read the chapter, then tick topics off individually rather than marking the whole chapter done. Sub-topics are where silent gaps hide.
Testing and Debugging in ExpressJS (ExpressJS) FAQ
What is in the ExpressJS Testing and Debugging in ExpressJS syllabus?
Testing and Debugging in ExpressJS is split into 3 chapters — Unit Testing, Integration Testing and Debugging Techniques, containing 7 topics and 0 sub-topics in total.
How many chapters are there in Testing and Debugging in ExpressJS for ExpressJS?
3 chapters. Testing and Debugging in ExpressJS accounts for about 13% of the topics in the whole ExpressJS syllabus (7 of 54).
How long should I spend on Testing and Debugging in ExpressJS for ExpressJS?
Budget around 5 hours for a first pass through Testing and Debugging in ExpressJS — about 45 minutes per topic plus 12 minutes per sub-topic across its 7 topics. Add revision cycles on top.
Are there flashcards for ExpressJS Testing and Debugging in ExpressJS?
Yes — a 50-card Testing and Debugging in ExpressJS deck. Sample cards are printed on this page, and the full deck is free in the Examius app with spaced repetition scheduling.