Skip to content

Commit

Permalink
t.type(fn, Function) should pass
Browse files Browse the repository at this point in the history
Close #354
  • Loading branch information
isaacs committed Jun 18, 2017
1 parent 8aa0d52 commit 1892366
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/asserts.js
Expand Up @@ -142,6 +142,14 @@ function decorate (t) {
type = 'null'
}

if (type === 'function' &&
typeof klass === 'function' &&
klass !== Object) {
// treat as object, but not Object
// t.type(() => {}, Function)
type = 'object'
}

if (type === 'object' && klass !== 'object') {
if (typeof klass === 'function') {
e.found = Object.getPrototypeOf(obj).constructor.name
Expand Down
11 changes: 11 additions & 0 deletions test/test/type-function--bail--buffer.tap
@@ -0,0 +1,11 @@
TAP version 13
ok 1 - type is Function
ok 2 - type is Function
ok 3 - type is Function
not ok 4 - type is Object
---
{"at":{"column":3,"file":"test/test/type-function.js","line":5},"compare":"===","found":"function","source":"t.type(t.type, Object)\n","wanted":"Object"}
...

Bail out! # type is Object

11 changes: 11 additions & 0 deletions test/test/type-function--bail.tap
@@ -0,0 +1,11 @@
TAP version 13
ok 1 - type is Function
ok 2 - type is Function
ok 3 - type is Function
not ok 4 - type is Object
---
{"at":{"column":3,"file":"test/test/type-function.js","line":5},"compare":"===","found":"function","source":"t.type(t.type, Object)\n","wanted":"Object"}
...

Bail out! # type is Object

23 changes: 23 additions & 0 deletions test/test/type-function--buffer.tap
@@ -0,0 +1,23 @@
TAP version 13
ok 1 - type is Function
ok 2 - type is Function
ok 3 - type is Function
not ok 4 - type is Object
---
{"at":{"column":3,"file":"test/test/type-function.js","line":5},"compare":"===","found":"function","source":"t.type(t.type, Object)\n","wanted":"Object"}
...

not ok 5 - type is Object
---
{"at":{"column":3,"file":"test/test/type-function.js","line":6},"compare":"===","found":"function","source":"t.type(function () {}, Object)\n","wanted":"Object"}
...

not ok 6 - type is Object
---
{"at":{"column":3,"file":"test/test/type-function.js","line":7},"compare":"===","found":"function","source":"t.type(new Function(), Object)\n","wanted":"Object"}
...

1..6
# failed 3 of 6 tests
___/# time=[0-9.]+(ms)?/~~~

7 changes: 7 additions & 0 deletions test/test/type-function.js
@@ -0,0 +1,7 @@
var t = require('../..')
t.type(t.type, Function)
t.type(function () {}, Function)
t.type(new Function(), Function)
t.type(t.type, Object)
t.type(function () {}, Object)
t.type(new Function(), Object)
23 changes: 23 additions & 0 deletions test/test/type-function.tap
@@ -0,0 +1,23 @@
TAP version 13
ok 1 - type is Function
ok 2 - type is Function
ok 3 - type is Function
not ok 4 - type is Object
---
{"at":{"column":3,"file":"test/test/type-function.js","line":5},"compare":"===","found":"function","source":"t.type(t.type, Object)\n","wanted":"Object"}
...

not ok 5 - type is Object
---
{"at":{"column":3,"file":"test/test/type-function.js","line":6},"compare":"===","found":"function","source":"t.type(function () {}, Object)\n","wanted":"Object"}
...

not ok 6 - type is Object
---
{"at":{"column":3,"file":"test/test/type-function.js","line":7},"compare":"===","found":"function","source":"t.type(new Function(), Object)\n","wanted":"Object"}
...

1..6
# failed 3 of 6 tests
___/# time=[0-9.]+(ms)?/~~~

0 comments on commit 1892366

Please sign in to comment.