Comparing version 1.0.0 to 1.1.0
@@ -22,3 +22,3 @@ "use strict" | ||
o.only = function(subject, predicate) {o(subject, only = predicate)} | ||
o.spy = function() { | ||
o.spy = function(fn) { | ||
var spy = function() { | ||
@@ -28,3 +28,10 @@ spy.this = this | ||
spy.callCount++ | ||
if (fn) return fn.apply(this, arguments) | ||
} | ||
if (fn) | ||
Object.defineProperties(spy, { | ||
length: {value: fn.length}, | ||
name: {value: fn.name} | ||
}) | ||
spy.args = [] | ||
@@ -31,0 +38,0 @@ spy.callCount = 0 |
{ | ||
"name": "ospec", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Noiseless testing framework", | ||
@@ -11,3 +11,5 @@ "main": "ospec.js", | ||
"author": "Leo Horie <lhorie@hotmail.com>", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"bin": "./bin/ospec", | ||
"repository": "lhorie/mithril.js#rewrite" | ||
} |
@@ -7,3 +7,3 @@ # ospec | ||
Version: 1.0 | ||
Version: 1.1 | ||
License: MIT | ||
@@ -121,2 +121,25 @@ | ||
A spy can also wrap other functions, like a decorator: | ||
```javascript | ||
//code to be tested | ||
var count = 0 | ||
function inc() { | ||
count++ | ||
} | ||
//test suite | ||
var o = require("ospec") | ||
o.spec("call()", function() { | ||
o("works", function() { | ||
var spy = o.spy(inc) | ||
spy() | ||
o(count).equals(1) | ||
}) | ||
}) | ||
``` | ||
### Asynchronous tests | ||
@@ -341,3 +364,3 @@ | ||
### Function o.spy() | ||
### Function o.spy([Function fn]) | ||
@@ -344,0 +367,0 @@ Returns a function that records the number of times it gets called, and its arguments |
@@ -52,2 +52,21 @@ "use strict" | ||
}) | ||
o("spy wrapping", function() { | ||
var spy = o.spy(function view(vnode){ | ||
this.drawn = true | ||
return {tag: "div", children: vnode.children} | ||
}) | ||
var children = [""] | ||
var state = {} | ||
var output = spy.call(state, {children: children}) | ||
o(spy.length).equals(1) | ||
o(spy.name).equals("view") | ||
o(spy.callCount).equals(1) | ||
o(spy.args.length).equals(1) | ||
o(spy.args[0]).deepEquals({children: children}) | ||
o(state).deepEquals({drawn: true}) | ||
o(output).deepEquals({tag: "div", children: children}) | ||
}) | ||
}) | ||
@@ -54,0 +73,0 @@ o.spec("async", function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
21971
290
413