My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Example1  
Example of how fakeQuery works
Updated Feb 4, 2010 by matr...@mac.com

fakeQuery Example

jQuery code

The following jQuery code has been taken from the jQuery homepage.

function doSomething(){
   $("p.neat").addClass("ohmy").show("slow");
}

The different ways to test this

The tests in this example are written in JsUnit format, you can easily adapt for different frameworks.

// start with a fresh fakeQuery
$$.reset();

// call the code to be tested
doSomething();

// stop recording calls now
$$.stopRecording();

// assert that show("slow") was called on the "p.neat" elements
assertTrue( $$.wasCalledOn("p.neat", "show", "slow") );

// Explicitly assert that calls were made:
assertTrue( $$.wasCalled($("p.neat")) );
assertTrue( $$.wasCalled($("p.neat").addClass("ohmy")) );
assertTrue( $$.wasCalled($("p.neat").addClass("ohmy").show("slow")) );

// Find the addClass call and make sure the first argument was "ohmy"
assertEquals( "ohmy", $$.lastCallTo.addClass.argument );

// Make sure that addClass was only called once
assertEquals(1, $$.getCallCount("addClass"));

// Make sure the show method was called once
assertEquals(1, $$.getCallCount("show"));

// Make sure the hide method was not called
assertEquals(0, $$.getCallCount("hide"));
Comment by ursula....@gmail.com, Jan 23, 2011

Heading1

Heading2

Heading3

bold italic inline code escape: *

Indent lists 2 spaces:

  • bullet item
  1. numbered list

verbatim code block

Horizontal rule ----

WikiWordLink? label http://domain/page

table cells


Sign in to add a comment
Powered by Google Project Hosting