1
ユーザーがログインした後でしかアクセスできないページの単体テストを書いています。ユーザーが正常に終了したかどうかをテストする次のコードがありますテスト作品ユーザーがログインする必要のあるWebページの単体テストを書く方法
describe('login', function() {
this.timeout(20000);
it('should login with correct password', function (done) {
this.timeout(20000);
setTimeout(done, 20000);
request.post('/login')
.send({
username:"[email protected]",
password:"admin1"
})
.expect('Location','/profile')
.end(done);
});
});
そして私はこのコードを追加しようとしました:中かログイン私は、ユーザーが秘密のページを取得することができるはず期待
describe('secret page',function(){
it('should get secret',function(done){
request.get('/secret')
.expect('Location','/secret')
.end(done);
});
});
が、私はエラーを受け取りました:
GET /secret 302 0.424 ms - 28
Error: expected "Location" of "/secret", got "/login"
at Test._assertHeader (\node_modules\supertest\lib\test.js:247:12)
at Test._assertFunction (\node_modules\supertest\lib\test.js:281:11)
at Test.assert (\node_modules\supertest\lib\test.js:171:18)
at Server.assert (\node_modules\supertest\lib\test.js:131:12)
at emitCloseNT (net.js:1554:8)
at _combinedTickCallback (internal/process/next_tick.js:77:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
最初の記述ブロックに2番目の "it"関数を入れようとしましたが、同じエラーが発生します。しかし、ウェブサイトが実行されている場合、ユーザーはログインページに戻るのではなく、シークレットページに正しく行くことができます。
コード全体を投稿できますか?リクエストは何をしますか?あなたは何を嘲笑しますか? – Ioan