Git Product home page Git Product logo

js-spec's Introduction

describe("js-spec", function() { with(this) {
  
  it("should pass when doing simple comparisons", function() {
    (1).should( equal(1) );
    (1).should( be_less_than(2) );
    (1).should( be_greater_than(0) );
    (1).should_not( equal(2) );
    (1).should_not( be(1) ); // 'be' checks if it's the same object
  });
  
  it("should pass when checking if a value is within a delta of another", function() {
    // first argument is the target, second one the maximum allowed difference between both numbers
    (1.0).should( be_close(1.05, 0.1) );
    (1.0).should_not( be_close(1.5, 0.1) );
  });
  
  it("should pass when checking if a method changes an object", function() {
    [1, 2, 3, 4].should_not( change("length").in_response_to("size") );
    // the next example would also pass if you changed 'to(3)' to 'from(4)' or 'by(-1)'
    [1, 2, 3, 4].should( change("length").to(3).in_response_to("pop") );
    // it also works for functions, and you can even pass parameters to them:
    [1, 2, 3, 4].should( change("first").to(0).in_response_to("unshift", 0) );
  });

  it("should pass when checking how many elements has an enumerable", function() {
    $("some_container").should( have(1, "childElements") );
    [1, 2, 3, 4].should( have(2, "slice", 0, 2) ); // equivalent to [1, 2, 3, 4].slice(0, 2).length.should( equal(2) )
    $("some_container").down("span").should_not( have_at_least(1, "childElements") );
    
  });
  
  it("should pass when asking if an enumerable includes some elements", function() {
    [1, 2, 3, 4].should( include(1, 2) );
    [1, 2, 3, 4].should_not( include(0) );
  })
  
  it("should match strings to regexps", function() {
    "to be or not to be".should_not( match(/^2b|[^b]{2}$/) );
    "Something".should( match(/^[Ss]/) );
  });

  it("should match DOM nodes to selectors correctly", function() {
    $("some_container").should( match("#some_container") );
    $("some_container").down(".something").should( match("#some_container .something") );
  });
  
  it("should pass when asking if an object responds to a method", function() {
    [1, 2, 3].should( respond_to("size") );
    "string".should_not( respond_to("asdfg") );
  });
  
  it("should pass when asking if an object satisfies a block", function() {
    [1, 2, 3].should( satisfy(function(list) {
      return list.length > 2;
    }));
    
    "string".should_not( satisfy(function(word) {
      return word.startsWith("cuack");
    }));
  });
  
}});

js-spec's People

Contributors

foca avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.