File: test.js

package info (click to toggle)
node-is-promise 4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 124 kB
  • sloc: javascript: 61; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var assert = require('assert');
var isPromise = require('./');

// `.then` methods on primative types should
// not make them count as promises
String.prototype.then = () => {};
Number.prototype.then = () => {};
Boolean.prototype.then = () => {};

assert(isPromise(null) === false);
assert(isPromise(undefined) === false);
assert(isPromise(0) === false);
assert(isPromise(-42) === false);
assert(isPromise(42) === false);
assert(isPromise('') === false);
assert(isPromise('then') === false);
assert(isPromise(false) === false);
assert(isPromise(true) === false);
assert(isPromise({}) === false);
assert(isPromise({then: true}) === false);
assert(isPromise([]) === false);
assert(isPromise([true]) === false);
assert(isPromise(() => {}) === false);

// This looks similar enough to a promise
// that promises/A+ says we should treat
// it as a promise.
var promise = {then: function () {}};

assert(isPromise(promise) === true);
const fn = () => {};
fn.then = () => {};
assert(isPromise(fn) === true);

console.log('tests passed')