Skip to content
This repository
  • 2 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
Mar 21, 2012
Sean McArthur mockXHR was parsing a string automatically as a query string, can't m…
…ake that assumption.

if a request was expecting JSON, it will be all wrong. now, each test needs to deserialize the passed string the way it expects it to be.
4d3f96c
Sean McArthur fixing test runner from trying to execute json files as test suites ad57caa
3  lib/shipyard/test/mockXHR.js
@@ -30,9 +30,6 @@ module.exports = function mockXHR(response, status) {
30 30
         open: new Spy(),
31 31
         send: new Spy(function(data) {
32 32
             if (handler) {
33  
-                if (typeOf(data) === 'string') {
34  
-                    data = string.parseQueryString(data);
35  
-                }
36 33
                 var response = handler.call(this, data);
37 34
                 if (typeOf(response) !== 'string') {
38 35
                     response = JSON.stringify(response);
8  scripts/test.js
@@ -31,9 +31,13 @@ exports.load = function load(dir, casesArgs, prefix) {
31 31
     }
32 32
     casesArgs.forEach(function(val) {
33 33
         var _p = path.join(dir, val);
34  
-        if (existsSync(_p) && fs.statSync(_p).isFile()) {
  34
+        if (!existsSync(_p)) {
  35
+            console.warn("Test doesn't exist: ", _p);
  36
+            return;
  37
+        }
  38
+        if (path.extname(_p) === '.js' && fs.statSync(_p).isFile()) {
35 39
             cases.push(namespace(prefix, require(_p)));
36  
-        } else {
  40
+        } else if (fs.statSync(_p).isDirectory()) {
37 41
             var _prefix = (prefix ? prefix+': ' : '') + val;
38 42
             load(_p, null, _prefix).forEach(function(_d) {
39 43
                 cases.push(_d);
4  test/unit/sync/server.js
... ...
@@ -1,7 +1,8 @@
1 1
 var ServerSync = require('../../../lib/shipyard/sync/Server'),
2 2
     Syncable = require('../../../lib/shipyard/sync/Syncable'),
3 3
     Class = require('../../../lib/shipyard/class/Class'),
4  
-    mockXHR = require('../../../lib/shipyard/test/mockXHR');
  4
+    mockXHR = require('../../../lib/shipyard/test/mockXHR'),
  5
+    string = require('../../../lib/shipyard/utils/string');
5 6
 
6 7
 module.exports = {
7 8
 
@@ -18,6 +19,7 @@ module.exports = {
18 19
         
19 20
         it('should save syncables', function(expect) {
20 21
             mockXHR(function(data) {
  22
+                data = string.parseQueryString(data);
21 23
                 expect(data).toBeLike({ foo: 'bar' });
22 24
                 return data;
23 25
             });
4  test/unit/test/mockXHR.js
... ...
@@ -1,5 +1,6 @@
1 1
 var mockXHR = require('../../../lib/shipyard/test/mockXHR'),
2  
-    Request = require('../../../lib/shipyard/http/Request');
  2
+    Request = require('../../../lib/shipyard/http/Request'),
  3
+    string = require('../../../lib/shipyard/utils/string');
3 4
 
4 5
 module.exports = {
5 6
     'mockXHR': function(it, setup) {
@@ -43,6 +44,7 @@ module.exports = {
43 44
 
44 45
         it('should accept a handler', function(expect) {
45 46
             mockXHR(function(data) {
  47
+                data = string.parseQueryString(data);
46 48
                 expect(data.a).toBe('moo');
47 49
                 return 'derp';
48 50
             });

No commit comments for this range

Something went wrong with that request. Please try again.