Skip to content

Commit 258bc69

Browse files
author
James Halliday
committed
use require() instead of eval() in the server test, setting globals for document and window with jsdom
1 parent 36021ee commit 258bc69

2 files changed

Lines changed: 128 additions & 126 deletions

File tree

test/server.js

Lines changed: 4 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -3,131 +3,9 @@
33

44
var fs = require('fs'),
55
should = require('should'),
6-
jsdom = require('jsdom').jsdom,
7-
document = jsdom(fs.readFileSync(__dirname + '/index.html').toString()),
8-
window = document.createWindow();
6+
jsdom = require('jsdom').jsdom;
97

10-
eval(fs.readFileSync(__dirname + '/../src/paypal-button.js').toString());
8+
global.document = jsdom(fs.readFileSync(__dirname + '/index.html').toString());
9+
global.window = document.createWindow();
1110

12-
// Test the object's integrity
13-
describe('PAYPAL.apps.ButtonFactory', function () {
14-
15-
'use strict';
16-
17-
it('Should have a PAYPAL object', function () {
18-
PAYPAL.should.be.a('object');
19-
});
20-
21-
it('Should have a PAYPAL.apps object', function () {
22-
PAYPAL.apps.should.be.a('object');
23-
});
24-
25-
it('Should have a PAYPAL.apps.ButtonFactory object', function () {
26-
PAYPAL.apps.ButtonFactory.should.be.a('object');
27-
});
28-
29-
});
30-
31-
// Test the create method
32-
describe('PAYPAL.apps.ButtonFactory.create', function () {
33-
34-
'use strict';
35-
36-
it('Should be a function', function () {
37-
PAYPAL.apps.ButtonFactory.create.should.be.a('function');
38-
});
39-
40-
it('Should return false if no parameters', function () {
41-
var result = PAYPAL.apps.ButtonFactory.create();
42-
43-
result.should.equal(false);
44-
});
45-
46-
it('Should return an element', function () {
47-
var result = PAYPAL.apps.ButtonFactory.create({
48-
business: '6XF3MPZBZV6HU',
49-
item: 'Buy now',
50-
amount: '1.00'
51-
});
52-
53-
result.should.be.a('object');
54-
});
55-
});
56-
57-
// Test the buttons counter object
58-
describe('PAYPAL.apps.ButtonFactory.buttons', function () {
59-
60-
'use strict';
61-
62-
it('Should have three buy now buttons', function () {
63-
var result = PAYPAL.apps.ButtonFactory.buttons.buynow;
64-
65-
result.should.equal(3);
66-
});
67-
68-
it('Should have six cart buttons', function () {
69-
var result = PAYPAL.apps.ButtonFactory.buttons.cart;
70-
71-
result.should.equal(6);
72-
});
73-
74-
it('Should have one QR code', function () {
75-
var result = PAYPAL.apps.ButtonFactory.buttons.qr;
76-
77-
result.should.equal(1);
78-
});
79-
});
80-
81-
// Test multi-language support
82-
describe('Multi-language button images', function () {
83-
84-
'use strict';
85-
86-
it('Should have a spanish version of Buy Now button', function () {
87-
var spanishButton = document.getElementById('buynowSpanish'),
88-
spanishImage = spanishButton.getElementsByTagName('input')[0].src;
89-
90-
spanishImage.should.include('es_ES');
91-
});
92-
93-
it('Should have a french version of Cart button', function () {
94-
var frenchButton = document.getElementById('cartFrench'),
95-
frenchImage = frenchButton.getElementsByTagName('input')[0].src;
96-
97-
frenchImage.should.include('fr_FR');
98-
});
99-
100-
it('Should have a german version of Hosted button', function () {
101-
var germanButton = document.getElementById('hostedGerman'),
102-
germanImage = germanButton.getElementsByTagName('input')[0].src;
103-
104-
germanImage.should.include('de_DE');
105-
});
106-
});
107-
108-
// Test multiple button image sizes
109-
describe('Multiple button image sizes', function () {
110-
111-
'use strict';
112-
113-
it('Should have a small version of Buy Now button', function () {
114-
var buynowSmallButton = document.getElementById('buynowSmall'),
115-
buynowSmallImg = buynowSmallButton.getElementsByTagName('input')[0].src;
116-
117-
buynowSmallImg.should.include('SM');
118-
});
119-
120-
it('Should have a small version of Cart button', function () {
121-
var cartSmallButton = document.getElementById('cartSmall'),
122-
cartSmallImg = cartSmallButton.getElementsByTagName('input')[0].src;
123-
124-
cartSmallImg.should.include('SM');
125-
});
126-
127-
it('Should have a small version of Hosted button', function () {
128-
var hostedSmallButton = document.getElementById('hostedSmall'),
129-
hostedSmallImg = hostedSmallButton.getElementsByTagName('input')[0].src;
130-
131-
hostedSmallImg.should.include('SM');
132-
});
133-
});
11+
require('./test.js');

test/test.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
var PAYPAL = require('../src/paypal-button.js');
2+
3+
// Test the object's integrity
4+
describe('PAYPAL.apps.ButtonFactory', function () {
5+
6+
'use strict';
7+
8+
it('Should have a PAYPAL object', function () {
9+
PAYPAL.should.be.a('object');
10+
});
11+
12+
it('Should have a PAYPAL.apps object', function () {
13+
PAYPAL.apps.should.be.a('object');
14+
});
15+
16+
it('Should have a PAYPAL.apps.ButtonFactory object', function () {
17+
PAYPAL.apps.ButtonFactory.should.be.a('object');
18+
});
19+
20+
});
21+
22+
// Test the create method
23+
describe('PAYPAL.apps.ButtonFactory.create', function () {
24+
25+
'use strict';
26+
27+
it('Should be a function', function () {
28+
PAYPAL.apps.ButtonFactory.create.should.be.a('function');
29+
});
30+
31+
it('Should return false if no parameters', function () {
32+
var result = PAYPAL.apps.ButtonFactory.create();
33+
34+
result.should.equal(false);
35+
});
36+
37+
it('Should return an element', function () {
38+
var result = PAYPAL.apps.ButtonFactory.create({
39+
business: '6XF3MPZBZV6HU',
40+
item: 'Buy now',
41+
amount: '1.00'
42+
});
43+
44+
result.should.be.a('object');
45+
});
46+
});
47+
48+
// Test the buttons counter object
49+
describe('PAYPAL.apps.ButtonFactory.buttons', function () {
50+
51+
'use strict';
52+
53+
it('Should have three buy now buttons', function () {
54+
var result = PAYPAL.apps.ButtonFactory.buttons.buynow;
55+
56+
result.should.equal(3);
57+
});
58+
59+
it('Should have six cart buttons', function () {
60+
var result = PAYPAL.apps.ButtonFactory.buttons.cart;
61+
62+
result.should.equal(6);
63+
});
64+
65+
it('Should have one QR code', function () {
66+
var result = PAYPAL.apps.ButtonFactory.buttons.qr;
67+
68+
result.should.equal(1);
69+
});
70+
});
71+
72+
// Test multi-language support
73+
describe('Multi-language button images', function () {
74+
75+
'use strict';
76+
77+
it('Should have a spanish version of Buy Now button', function () {
78+
var spanishButton = document.getElementById('buynowSpanish'),
79+
spanishImage = spanishButton.getElementsByTagName('input')[0].src;
80+
81+
spanishImage.should.include('es_ES');
82+
});
83+
84+
it('Should have a french version of Cart button', function () {
85+
var frenchButton = document.getElementById('cartFrench'),
86+
frenchImage = frenchButton.getElementsByTagName('input')[0].src;
87+
88+
frenchImage.should.include('fr_FR');
89+
});
90+
91+
it('Should have a german version of Hosted button', function () {
92+
var germanButton = document.getElementById('hostedGerman'),
93+
germanImage = germanButton.getElementsByTagName('input')[0].src;
94+
95+
germanImage.should.include('de_DE');
96+
});
97+
});
98+
99+
// Test multiple button image sizes
100+
describe('Multiple button image sizes', function () {
101+
102+
'use strict';
103+
104+
it('Should have a small version of Buy Now button', function () {
105+
var buynowSmallButton = document.getElementById('buynowSmall'),
106+
buynowSmallImg = buynowSmallButton.getElementsByTagName('input')[0].src;
107+
108+
buynowSmallImg.should.include('SM');
109+
});
110+
111+
it('Should have a small version of Cart button', function () {
112+
var cartSmallButton = document.getElementById('cartSmall'),
113+
cartSmallImg = cartSmallButton.getElementsByTagName('input')[0].src;
114+
115+
cartSmallImg.should.include('SM');
116+
});
117+
118+
it('Should have a small version of Hosted button', function () {
119+
var hostedSmallButton = document.getElementById('hostedSmall'),
120+
hostedSmallImg = hostedSmallButton.getElementsByTagName('input')[0].src;
121+
122+
hostedSmallImg.should.include('SM');
123+
});
124+
});

0 commit comments

Comments
 (0)