Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default expectations #14

Open
lgomez opened this issue Jan 29, 2016 · 1 comment
Open

Default expectations #14

lgomez opened this issue Jan 29, 2016 · 1 comment

Comments

@lgomez
Copy link

lgomez commented Jan 29, 2016

Hello,

I'd like to use this module but I'm having a hard time figuring out if it's possible to set default expectations. Specifically, I want all my calls to .expect('Content-Type', /json/) but, when I add that to the defaults I get:

/Users/lgomez/Projects/api/test/index.js:6
  .expect('Content-Type', /json/);
   ^

TypeError: api.set(...).expect is not a function
    at Object.<anonymous> (/Users/lgomez/Projects/api/test/index.js:6:4)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at /Users/lgomez/Projects/api/node_modules/mocha/lib/mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/lgomez/Projects/api/node_modules/mocha/lib/mocha.js:213:14)
    at Mocha.run (/Users/lgomez/Projects/api/node_modules/mocha/lib/mocha.js:453:10)
    at Object.<anonymous> (/Users/lgomez/Projects/api/node_modules/mocha/bin/_mocha:393:18)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:138:18)
    at node.js:974:3

This is how I'm running it:

var defaults = require('superagent-defaults');

var api = defaults(require('supertest')(require('../server'))); // ..server is an expressjs app

api
    .set('Accept', 'application/json')
    .expect('Content-Type', /json/);

describe('/users', function() {

  it('accepts email and password as auth payload', function(done) {

    api.post('/users/auth')
      .send({
        email: '[email protected]',
      })
      .expect(200, done);
  });

});
@lgomez
Copy link
Author

lgomez commented Jan 29, 2016

Oh... btw, line numbers in the error will not map to the example above because I truncated some sensitive info out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant