Sham
Sham is a simple and small JavaScript library for mocking.
sham.spy([name])
var sum = sham; sum; // specify the argumentssum; // set return valuesum; // ensure that spy is called three times // this throws an error, because the arguments are wrong var result = ; // result is now 12 sum; // this throws an error, because sum was called only once
sham.mock()
var file = sham; filemethod'read';filemethod'write'; var contents = file; // contents is now 'some text' file; // this throws an error, because write wasn't called file; file; // this doesn't throw
You can generate mocks too:
{ var file = sham; filemethod'read'; filemethod'write'; return file;} var file = ; fileread; var contents = file; // contents is now 'some text'