Giter Club home page Giter Club logo

dexterjs's Introduction

Dexter JS

Dexter is a simple Test Helper to mock and spy methods and to fake the Ajax interface. It's framework independent, running with QUnit, Jasmine, Mocha, etc.

Build Status Coverage Status

Getting Started

Download the minified version or the development version.

You may also install Dexter from NPM or Bower:

  • NPM: npm install --save-dev dexter
  • Bower: bower install --save-dev dexter

Or build your own copy.

Support

Dexter is supported and tested on:

Node

  • 0.10+

Desktop

  • Firefox 4+
  • Chrome 18+
  • Internet Explorer 9+
  • Safari 7+ (Mac OS)

Mobile

  • Firefox for Android 23+
  • Firefox OS
  • Chrome (Android)
  • iOS 6+

Documentation

The project documentation files are located in https://github.com/leobalter/DexterJS/tree/master/docs

Build

By git cloning this repository you can build your own copy.

First, install the grunt-cli if you haven't before. This should be installed globally (like this: npm install -g grunt-cli).

Then install the project dependencies:

npm install

And build the distribution files:

grunt

The Contributors Hall

You are welcome to join us on the list of contributors for this project on Github.

Please, check the Contributing documentation, there're just a few steps.

License

Copyright (c) 2014 Leonardo Balter && Luan Muniz Licensed under the MIT and GPL licenses.

dexterjs's People

Contributors

bitdeli-chef avatar heldr avatar leobalter avatar luanmuniz avatar raphamorim avatar ruanmer 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar

dexterjs's Issues

README's correction

In the last line of Dexter.spy Example, the object isn't spy? _spy.restore()_

// you can restore the spied method to it's default functionality
stub.restore();

And congratz, man. Great job! :)

create fakeAjax

create fakeAjax method.

This should block real ajax methods, it´s an improved stub? humm, I would try that.

Add XHR2 callback support

Hello,

I started using DexterJS for testing my ajax requests, and I really enjoy it so far.
However, I am using JQuery 2 and I found out that the only callback supported in master is onreadystatechange. Unfortunately, JQuery2 wants to use onload and friends.

I quickly tweaked my local copy's __DexterStateChange to invoke onload when switching the state to DONE. That gets me going for now, but it is by no mean a clean solution. Proper support for the new callbacks would be awesome if someone fins the time to do it.

Cannot assume 'window' exists.

Hey! Trying to use this library via the Dojo AMD loader and having trouble when calling
var fakeXHR = Dexter.fakeXHR();:

Defaulting to "console" reporter
ReferenceError: window is not defined
    at /Users/vladikoff/mozilla/fxa-js-client/node_modules/dexter/dist/dexter.js:96:9
    at /Users/vladikoff/mozilla/fxa-js-client/node_modules/dexter/dist/dexter.js:109:2
    at Function.vm.runInThisContext (/Users/vladikoff/mozilla/fxa-js-client/node_modules/intern/node_modules/istanbul/lib/hook.js:163:16)
    at /Users/vladikoff/mozilla/fxa-js-client/node_modules/intern/node_modules/dojo/dojo.js:757:8
    at fs.js:266:14
    at Object.oncomplete (fs.js:107:15)

Code Issue:

    if ( typeof module === 'undefined' || typeof module.exports === 'undefined' ) {
        window.Dexter = Dexter;
    } else {

I'll try to PR a fix if I have time.

Clarify fakeXHR documentation

Regarding @spectras comment on #22, we can improve our fakeXHR documentation.

Here are some gotchas that might find their way into the documentation by the way:

  • I added fakeXHR.requests = [] to my QUnit module's setup to ensure my tests are independent. Otherwise, I might end up responding to requests from another testcase. If fakeXHR.requests is considered as an internal api, maybe it would be useful to add an accessor method?
  • I use requireJS:
    • I looked for fakeXHR for a while before I realized I had to add it as a requirement (define(['fakeXHR', 'dexter', ...] function (fakeXHR, dexter, ...) {).
    • to have fakeXHR work fine it needs a fakeXHR: "dexter" entry in the path configuration so it knows it is loaded from the same file as dexter.
    • apart from that, dexterjs plays surprinsingly well with requireJS.

Remove fake ajax feature

This would make a new major version, but after a discussion at jquery/pull#2737 I wonder this library would work better without mocking the ajax API as it can be solved through other libraries available on NPM.

Closes #23
Closes #22

Global Dexter.restore()

Hi,

I would to suggest a global Dexter.restore() that can be used to restore all called stubs instead of invoking it one by one.

This will make more easier to use DexterJS using a hook like this:

describe("something", function () {
  after(function () {
    Dexter.restore();
  });

  it("should do something", function () {
    Dexter.stub( window, 'something', function() {
      return 10;
    });

    window.something.should.equal(10);
  });

  it("should do something else", function () {
    Dexter.stub( window, 'something', function() {
      return 20;
    });

    window.something.should.equal(20);
  });
});

If you agree, I would to make a pull request :)

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.