forked from MrSwitch/hello.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-api.js
40 lines (31 loc) · 915 Bytes
/
test-api.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
describe('Hello API', function(){
//
// Are errors thrown if an invalid network is provided
//
describe('dataToJSON', function(){
it('should extrapolate the data in a form', function(){
// Create a form
document.body.innerHTML = "<form id='form'>"+
["<input name='key' value='value'/>",
"<input name='key2' value='value2'/>",
"<input name='file' type='file'/>"].join()+
"</form>";
// Make request
var obj = {
data : document.getElementById('form')
};
var bool = hello.utils.dataToJSON(obj);
if(bool){
// This has been altered to a JSON object
expect( obj.data ).to.be.a("object");
expect( obj.data.key ).to.be("value");
expect( obj.data.key2 ).to.be("value2");
expect( obj.data.file ).to.be.a("object");
}
else{
// The data object can't be altered
expect( obj.data.tagName.toUpperCase() ).to.be( "FORM" );
}
});
});
});