Supertest中的否定断言

初学者用Javascript进行testing。 我正在使用摩卡,但路易聪明地没有说这个问题是摩卡特有的。 我有一个节点应用程序,有一些匿名用户可见的页面,有些则不应该能够看到你是否没有login。所以,作为一个非常简单的开始,

describe('User Access', function(){ it('should allow anyone to access the help desk (about page)', function(done){ request(host) .get('/') .expect(200, done); }), it('should allow anyone to access the contact page', function(done){ request(host) .get('/contact') .expect(200, done); }), //initially we were expecting 404, we need anything BUT 200. it('should NOT allow anonymous user to access the Training Material page', function(done){ request(host) .get('/training') .expect(404, done); }), 

等等

这工作,最初。 但是,开发人员已经将不可用页​​面更改为302状态,并将其redirect到Web应用程序的根目录。 所以,为了让开发者能够灵活地实现这个限制,我想把这个改成一个负面的断言。 所以,使用摩卡的语法,我怎么“期待”的反应是什么,但200?

在这里的文档说,你可以传入一个自定义的断言函数给予响应对象,从该函数返回一个值将意味着断言失败,即;

 .expect(function(res){ if(res.status == 200){ return "we dont like 200!"; } })