LiTiang / js-test-driver

Automatically exported from code.google.com/p/js-test-driver
0 stars 0 forks source link

ajax failed #288

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Here is example from wiki (AsyncTestCase)

var XhrTest = AsyncTestCase('XhrTest');

XhrTest.prototype.testRequest = function(queue) {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', 'http://localhost/site/ci');

  var responseBody = 0;

  queue.call('Step 1: send a request to the server and save the response body', function(callbacks) {
    var onStatusReceived = callbacks.add(function(status) {
      assertEquals(200, status);
    });

    var onBodyReceived = callbacks.add(function(body) {
      responseBody = body;
      responseBody = 1;
    });

    xhr.onreadystatechange = function() {
      if (xhr.readyState == 2) { // headers and status received
        onStatusReceived(xhr.status);
      } else if (xhr.readyState == 4) { // full body received
        onBodyReceived(xhr.responseText);
      }
    };

    xhr.send(null);
  });

  queue.call('Step 2: assert the response body matches what we expect', function() {
    assertEquals(1, responseBody);
  });
};

This code (without queue.call) works wonderfull without js-test-driver.

What steps will reproduce the problem?
1. starting server - java -jar JsTestDriver-1.3.3d.jar --port 9876
2. execute - java -jar JsTestDriver-1.3.3d.jar --config ./test.conf --tests all 
--browser '/usr/bin/firefox'

What is the expected output? 

Test passed.

What do you see instead?

Test failed. Request was failed with status 304.

F
Total 1 tests (Passed: 0; Fails: 1; Errors: 0) (630,00 ms)
  Firefox 7.0.1 Linux: Run 1 tests (Passed: 0; Fails: 1; Errors 0) (630,00 ms)
    XhrTest.testRequest failed (630,00 ms): AssertError: expected 200 but was 0
      (0)@http://localhost:4224/test/testfff.js:11
      ([object Event])@http://localhost:4224/test/testfff.js:21
Tests failed: Tests failed. See log for details.

What version of the product are you using? On what operating system?

JsTestDriver-1.3.3d, Linux Debian 2.6.32-5-amd64, Mozilla Firefox 7.0.1

Please provide any additional information below.

File test.conf

server: http://localhost:4224
load:
    - testfff.js

Original issue reported on code.google.com by DimaSKor...@gmail.com on 2 Nov 2011 at 11:02

GoogleCodeExporter commented 9 years ago
So, this is entirely dependent on how you've set up the server on localhost. 
Obviously, the browser has cached the result you are looking for. 

JsTD does nothing to the existing XMLHttpRequest.

Original comment by corbinrs...@gmail.com on 12 Dec 2011 at 5:45