Home / Function/ test() — express Function Reference

test() — express Function Reference

Architecture documentation for the test() function in res.format.js from the express codebase.

Entity Profile

Dependency Diagram

graph TD
  8d4204d7_6201_9255_3e91_fb39be42eca6["test()"]
  4ac0e6ff_0877_0a0f_9070_b23deca5c052["res.format.js"]
  8d4204d7_6201_9255_3e91_fb39be42eca6 -->|defined in| 4ac0e6ff_0877_0a0f_9070_b23deca5c052
  style 8d4204d7_6201_9255_3e91_fb39be42eca6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

test/res.format.js lines 182–248

function test(app) {
  it('should utilize qvalues in negotiation', function(done){
    request(app)
    .get('/')
    .set('Accept', 'text/html; q=.5, application/json, */*; q=.1')
    .expect({"message":"hey"}, done);
  })

  it('should allow wildcard type/subtypes', function(done){
    request(app)
    .get('/')
    .set('Accept', 'text/html; q=.5, application/*, */*; q=.1')
    .expect({"message":"hey"}, done);
  })

  it('should default the Content-Type', function(done){
    request(app)
    .get('/')
    .set('Accept', 'text/html; q=.5, text/plain')
    .expect('Content-Type', 'text/plain; charset=utf-8')
    .expect('hey', done);
  })

  it('should set the correct charset for the Content-Type', function (done) {
    var cb = after(3, done)

    request(app)
    .get('/')
    .set('Accept', 'text/html')
    .expect('Content-Type', 'text/html; charset=utf-8', cb)

    request(app)
    .get('/')
    .set('Accept', 'text/plain')
    .expect('Content-Type', 'text/plain; charset=utf-8', cb)

    request(app)
    .get('/')
    .set('Accept', 'application/json')
    .expect('Content-Type', 'application/json; charset=utf-8', cb)
  })

  it('should Vary: Accept', function(done){
    request(app)
    .get('/')
    .set('Accept', 'text/html; q=.5, text/plain')
    .expect('Vary', 'Accept', done);
  })

  describe('when Accept is not present', function(){
    it('should invoke the first callback', function(done){
      request(app)
      .get('/')
      .expect('hey', done);
    })
  })

  describe('when no match is made', function(){
    it('should respond with 406 not acceptable', function(done){
      request(app)
      .get('/')
      .set('Accept', 'foo/bar')
      .expect('Supports: text/plain, text/html, application/json')
      .expect(406, done)
    })
  })
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does test() do?
test() is a function in the express codebase, defined in test/res.format.js.
Where is test() defined?
test() is defined in test/res.format.js at line 182.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free