-
Notifications
You must be signed in to change notification settings - Fork 33
/
browser.context.test.js
71 lines (60 loc) · 1.78 KB
/
browser.context.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Module dependencies.
*/
var tobi = require('tobi')
, express = require('express')
, Browser = tobi.Browser
, should = require('should');
// Test app
var app = express.createServer();
app.use(express.bodyDecoder());
app.get('/search', function(req, res){
res.send(
'<div><form id="user-search" method="post" action="/search/users">'
+ ' <input type="text" name="query" />'
+ '</form></div>'
+ '<div><form id="post-search" method="post" action="/search/posts">'
+ ' <input type="text" name="query" />'
+ '</form></div>');
});
app.post('/search/users', function(req, res){
res.send({ users: true, headers: req.headers, body: req.body });
});
app.post('/search/posts', function(req, res){
res.send({ posts: true, headers: req.headers, body: req.body });
});
module.exports = {
'test global context': function(done){
var browser = tobi.createBrowser(app);
browser.get('/search', function(res, $){
$('form').should.have.length(2);
browser
.type('query', 'foo bar')
.submit(function(res){
res.body.should.have.property('users', true);
res.body.body.should.eql({ query: 'foo bar' });
done();
});
});
},
'test custom context': function(done){
var browser = tobi.createBrowser(app);
browser.get('/search', function(res, $){
$('form').should.have.length(2);
browser.within('div:nth-child(2)', function(){
$('form').should.have.length(1);
browser
.type('query', 'foo bar')
.submit(function(res){
res.body.should.have.property('posts', true);
res.body.body.should.eql({ query: 'foo bar' });
done();
});
});
$('form').should.have.length(2);
});
},
after: function(){
app.close();
}
};