with.js
3.12 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var expect = require('expect.js');
describe("Spooky provides Casper's with* functions", function () {
var context = {};
var hooks = require('../util/hooks');
var FIXTURE_URL = hooks.FIXTURE_URL;
beforeEach(hooks.before(context));
describe('spooky.withFrame', function () {
it('throws if its step is not a function',
function (done) {
context.spooky.swallowErrors = true;
context.spooky.once('error', function (e) {
expect(e.message.toLowerCase()).to.
contain('cannot parse function');
done();
});
context.spooky.withFrame(0, 'I am not a valid function');
});
it('performs its step in the context of the frame', function (done) {
context.spooky.start(FIXTURE_URL + '/frames.html');
context.spooky.withFrame('frame1', function () {
var expected = 'One';
var title = this.evaluate(function () {
return document.title;
});
if (title !== expected) {
throw new Error(
'expected title === ' + expected + ', but is ' + title);
}
});
context.spooky.withFrame('frame2', function () {
var expected = 'Two';
var title = this.evaluate(function () {
return document.title;
});
if (title !== expected) {
throw new Error(
'expected title === ' + expected + ', but is ' + title);
}
this.emit('done');
});
context.spooky.on('done', done);
context.spooky.run();
});
});
describe('spooky.withPopup', function () {
it('throws if its second argument is not a function',
function (done) {
context.spooky.swallowErrors = true;
context.spooky.once('error', function (e) {
expect(e.message.toLowerCase()).to.
contain('cannot parse function');
done();
});
context.spooky.withPopup(0, 'I am not a valid function');
});
it('performs its step in the context of the popup', function (done) {
context.spooky.start(FIXTURE_URL + '/popup.html');
context.spooky.thenClick('#popup1');
context.spooky.waitForPopup('1.html');
context.spooky.withPopup('1.html', function () {
var expected = 'One';
var title = this.evaluate(function () {
return document.title;
});
if (title !== expected) {
throw new Error(
'expected title === ' + expected + ', but is ' + title);
}
this.emit('done');
});
context.spooky.on('done', done);
context.spooky.run();
});
});
afterEach(hooks.after(context));
});