Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

expect.js

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expect.js - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

74

expect.js

@@ -20,3 +20,3 @@

expect.version = '0.1.1';
expect.version = '0.1.2';

@@ -120,9 +120,14 @@ /**

/**
* Asser that the function throws.
* Assert that the function throws.
*
* @param {Function|RegExp} callback, or regexp to match error string against
* @api public
*/
Assertion.prototype.throwException = function () {
Assertion.prototype.throwError =
Assertion.prototype.throwException = function (fn) {
expect(this.obj).to.be.a('function');
var thrown = false;
var thrown = false
, not = this.flags.not

@@ -132,5 +137,21 @@ try {

} catch (e) {
if ('function' == typeof fn) {
fn(e);
} else if ('object' == typeof fn) {
var subject = 'string' == typeof e ? e : e.message;
if (not) {
expect(subject).to.not.match(fn);
} else {
expect(subject).to.match(fn);
}
}
thrown = true;
}
if ('object' == typeof fn && not) {
// in the presence of a matcher, ensure the `not` only applies to
// the matching.
this.flags.not = false;
}
var name = this.obj.name || 'fn';

@@ -150,5 +171,21 @@ this.assert(

Assertion.prototype.empty = function () {
expect(this.obj).to.have.property('length');
var expectation;
if ('object' == typeof this.obj && null !== this.obj && !isArray(this.obj)) {
if ('number' == typeof this.obj.length) {
expectation = !this.obj.length;
} else {
expectation = !keys(this.obj).length;
}
} else {
if ('string' != typeof this.obj) {
expect(this.obj).to.be.an('object');
}
expect(this.obj).to.have.property('length');
expectation = !this.obj.length;
}
this.assert(
0 === this.obj.length
expectation
, 'expected ' + i(this.obj) + ' to be empty'

@@ -214,7 +251,13 @@ , 'expected ' + i(this.obj) + ' to not be empty');

if ('string' == typeof type) {
// proper english in error msg
var n = /^[aeiou]/.test(type) ? 'n' : '';
// typeof with support for 'array'
this.assert(
'array' == type ? isArray(this.obj) : type == typeof this.obj
, 'expected ' + i(this.obj) + ' to be a ' + type
, 'expected ' + i(this.obj) + ' not to be a ' + type);
'array' == type ? isArray(this.obj) :
'object' == type
? 'object' == typeof this.obj && null !== this.obj
: type == typeof this.obj
, 'expected ' + i(this.obj) + ' to be a' + n + ' ' + type
, 'expected ' + i(this.obj) + ' not to be a' + n + ' ' + type);
} else {

@@ -318,4 +361,11 @@ // instanceof

} else {
var hasProp;
try {
hasProp = name in this.obj
} catch (e) {
hasProp = undefined !== this.obj[name]
}
this.assert(
undefined !== this.obj[name]
hasProp
, 'expected ' + i(this.obj) + ' to have a property ' + i(name)

@@ -458,2 +508,6 @@ , 'expected ' + i(this.obj) + ' to not have a property ' + i(name));

if (arr.length === undefined) {
return -1;
}
for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0

@@ -460,0 +514,0 @@ ; i < j && arr[i] !== o; i++);

0.1.2 / 2012-02-04
==================
* Added regexp matching support for exceptions.
* Added support for throwException callback.
* Added `throwError` synonym to `throwException`.
* Added object support for `.empty`.
* Fixed `.a('object')` with nulls, and english error in error message.
* Fix bug `indexOf` (IE). [hokaccha]
* Fixed object property checking with `undefined` as value. [vovik]
0.1.1 / 2011-12-18

@@ -3,0 +14,0 @@ ==================

2

package.json
{
"name": "expect.js"
, "version": "0.1.1"
, "version": "0.1.2"
, "description": "BDD style assertions for node and the browser."

@@ -5,0 +5,0 @@ , "main": "./expect"

@@ -1,2 +0,1 @@

# Expect

@@ -29,3 +28,3 @@

```
$ npm install expect
$ npm install expect.js
```

@@ -163,3 +162,3 @@

For example, if you create a test suite with
[mocha](http://github.com/visionmedia.mocha).
[mocha](http://github.com/visionmedia/mocha).

@@ -215,3 +214,3 @@ Let's say we wanted to test the following program:

and point your browser(s) to `http://localhost:3000`
and point your browser(s) to `http://localhost:3000/test/`

@@ -218,0 +217,0 @@ ## Credits

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc