Giter VIP home page Giter VIP logo

foounit's People

Contributors

davidaurelio avatar foobarfighter avatar peterbraden avatar polotek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

foounit's Issues

Add xdescribe keyword

All nested tests under an xdescribe block should be marked as pending. This is much nicer than commenting out an entire spec file.

add env keyword for specifying the environment in which a test should run at runtime

Here are some ideas

// when calling env right before a describe or an 'it' block it only runs that test in that particular environment
env('node', 'browser');
describe('runs in node and the browser but not in air', function (){
...
});

or

// env can double as a describe
env('node', 'this doubles as a describe block', function (){
});

Documentation: What is BDD?

You are mentioning BDD everywhere on your website foounit.org and in the documentation. For a ignorant like me, it would be nice to have a quick introduction or a least some links to what that means. Hope I'm not being to nitpicking.

when a before fails the corresponding after is not run

This may only be true for before blocks that run asynchronous blocks. Example (waitFor fails):

describe('foounit.server.loader', function (){
var server, client;

before(function (){
  server = TestServer.start('0.0.0.0', 5999);
  client = new TestClient('0.0.0.0.', 5999);

  client.get('/status');

  waitFor(function (){
    var response = client.inbox.takeNext();
    console.log(response.body);
    expect(response.body.indexOf('status:')).to(beGt, -1);
  });
});

after(function (){
  server.stop();
  client.stop();
});

it('passes', function (){
  console.log('w00t!');
});

});

add more waitFor intelligence or a new keyword like ensure

// TODO: This would be cool.
run(function (){
client.get('/status');
});

// ensure would rerun the "run" block previous after it timed-out
// it would continue to rerun the "run" block until it timed-out N times
ensure(function (){
response = client.inbox.takeNext();
expect(response.body).to(include, 'status:');
});

Param with name "module" can break packages in browser tests

Hey man. Loving foounit so far!

I just wanted to let you know an issue I ran into working to add foounit browser tests to EpicEditor - which relies on Marked.

Seems like passing a param with the name module will break packages that rely on that keyword to check environment. More and more packages are doing things like this to try to be flexible enough to run in multiple contexts. In this case, it looks like Marked is added to the incorrect - or at least different/unexpected - scope.

Example:

(function(){
  if (typeof module !== 'undefined') {
    module.exports = marked;
  } else {
    this.marked = marked;
  }
}).call(this);

(function (window, undefined) {
  // Some other module
})(window);

foounit-browser.js

this.require = function (path){
    var code = get(path)
      , module = { exports: {} }
      , funcString = '(function (foounit, module, exports, __dirname, __filename){' + code + '});';

    try {
      var func = leval(funcString, path);
      func.call({}, foounit, module, module.exports, dirname(path), basename(path));
    } catch (e){
      console.error('Failed to load path: ' + path + ': ' + e.message, e);
    }

    return module.exports;
  };

I couldn't see where this was being used so I just removed references to module and exports as a temporary fix.

Let me know if I am missing something here. Maybe there is another way to wrap the code so that it doesn't cause conflicts, or maybe we should be setting up differently on our end?

Thanks.

mock should call the stub function in the correct context

When using mock to test ajax calls I ran into this issue.

      var req = {
        url: 'foo'
        , method: 'POST'
        , beforeSend: function() {
          expect(this.method).to(equal, 'POST');
          expect(this.type).to(equal, 'POST');
        }
      }

      req.beforeSend = mock(req, 'beforeSend', req.beforeSend);
      makeRequest(req);

      waitFor(function() {
        expect(req.beforeSend).to(haveBeenCalled);
      }, 1000);

This fails because in the beforeSend function, this is actually not the original request object, but a new object that has been "normalized" by adding/modifying some values. But once beforeSend is mocked, it is always called with the original context. Instead the stub function should be called with the current value of this.

Better Tracebacks in IE

Also, to save stress it would be cool if the IE tracebacks were really apologetic:

"IE6 failed at running this test, but it fails at lots of things, it's probably not you. We're very sorry, here's a link to a picture of a kitten. And a traceback:"

Test context should be shared by before and after

Right now it looks like each test gets a unique context (e.g. this). But the context should be shared by the before() and after() methods. This enables you to set up test-specific state and clean it up without polluting each actual test or polluting the closure scope. See example.

describe('testing the context', function() {
  before(function() {
    this.foo = 'unit';
  });

  after(function() {
    this.foo = null;
  });

  it('should have the context set', function() {
    expect(this.foo).to(be, 'unit');
  });
});

The test context should probably be cleared out after each test too. e.g. all properties set to null.

setTimeout/setInterval do not catch errors

Foounit has waitFor and waitForTimeout keywords for doing asynchronous testing. But these aren't good for the simple use case of running a simple function once. What I'm doing is mocking ajax calls. Here's a simplified example.

var fakeAjax = {
   send: function(req) {
      var fakexhr;
      foounit.setTimeout(function() {
          req.success && req.success('data', 'success', fakeXHR);
      }, 10);
   }
}

The problem comes in when I want to put expect statements inside the success function. Since setTimeout isn't test aware, the errors propagate to the top of the runtime but do not make the test fail. Here's the simplest test for this issue.

foounit.add(function (kw){ with (kw){
  describe('waitFor', function() {
    it('fails if timeout throws', function() {
      var end = false;
      foounit.setTimeout(function() {
        end = true;
        expect(false).to(beTrue);
      }, 100);

      waitFor(function() {
        expect(end).to(beTrue);
      }, 1000);
    });
  });
}});

This test passes, but the expect in setTimeout should be caught and cause it to fail.

Add mockEmpty

Creates a mocked function with an empty implementation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.