You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
483 B

8 years ago
  1. 'use strict'
  2. const arrayify = require('array-back')
  3. exports.checkResponse = checkResponse
  4. exports.fail = fail
  5. function checkResponse (t, status, bodyTests) {
  6. return function (response) {
  7. if (status) t.strictEqual(response.res.statusCode, status)
  8. if (bodyTests) {
  9. arrayify(bodyTests).forEach(body => {
  10. t.ok(body.test(response.data), 'correct data')
  11. })
  12. }
  13. }
  14. }
  15. function fail (t) {
  16. return function (err) {
  17. t.fail('failed: ' + err.stack)
  18. }
  19. }