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

chai-changes

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-changes - npm Package Compare versions

Comparing version 0.8.2 to 1.0.1

36

chai-changes.js

@@ -25,3 +25,3 @@ // Generated by CoffeeScript 1.3.3

chai.Assertion.addMethod('when', function(val, options) {
var action, definedActions, done, result, _i, _j, _len, _len1, _results,
var action, definedActions, done, object, promiseCallback, result, _i, _j, _len, _len1,
_this = this;

@@ -32,2 +32,4 @@ if (options == null) {

definedActions = flag(this, 'whenActions') || [];
object = flag(this, 'object');
flag(this, 'whenObject', object);
for (_i = 0, _len = definedActions.length; _i < _len; _i++) {

@@ -40,3 +42,4 @@ action = definedActions[_i];

result = val();
if (result.then != null) {
flag(this, 'object', result);
if ((result != null ? result.then : void 0) != null) {
done = options != null ? options.notify : void 0;

@@ -46,3 +49,3 @@ if (done == null) {

}
return result.then(function() {
promiseCallback = function() {
var _j, _len1;

@@ -58,13 +61,16 @@ try {

} catch (error) {
return done(new Error(error));
done(new Error(error));
throw new Error(error);
}
});
};
result.then(promiseCallback, promiseCallback);
} else {
_results = [];
for (_j = 0, _len1 = definedActions.length; _j < _len1; _j++) {
action = definedActions[_j];
_results.push(typeof action.after === "function" ? action.after(this) : void 0);
if (typeof action.after === "function") {
action.after(this);
}
}
return _results;
}
return this;
});

@@ -79,3 +85,3 @@ noChangeAssert = function(context) {

flag(context, 'negate', this.negate);
object = flag(context, 'object');
object = flag(context, 'whenObject');
startValue = flag(context, 'changeStart');

@@ -91,3 +97,3 @@ endValue = object();

flag(context, 'negate', this.negate);
object = flag(context, 'object');
object = flag(context, 'whenObject');
startValue = flag(context, 'changeStart');

@@ -103,3 +109,3 @@ endValue = object();

flag(context, 'negate', this.negate);
object = flag(context, 'object');
object = flag(context, 'whenObject');
startValue = object();

@@ -117,3 +123,3 @@ result = !utils.eql(startValue, this.expectedEndValue);

flag(context, 'negate', this.negate);
object = flag(context, 'object');
object = flag(context, 'whenObject');
endValue = object();

@@ -128,3 +134,3 @@ result = utils.eql(endValue, this.expectedEndValue);

flag(context, 'negate', this.negate);
object = flag(context, 'object');
object = flag(context, 'whenObject');
startValue = object();

@@ -139,3 +145,3 @@ result = utils.eql(startValue, this.expectedStartValue);

flag(context, 'negate', this.negate);
object = flag(context, 'object');
object = flag(context, 'whenObject');
startValue = flag(context, 'changeStart');

@@ -158,3 +164,3 @@ endValue = object();

var startValue;
startValue = flag(context, 'object')();
startValue = flag(context, 'whenObject')();
return flag(context, 'changeStart', startValue);

@@ -161,0 +167,0 @@ },

@@ -6,3 +6,3 @@ {

"keywords": [ "test", "assertion", "assert", "testing", "changes", "promises" ],
"version": "0.8.2",
"version": "1.0.1",
"repository": {

@@ -9,0 +9,0 @@ "type": "git",

@@ -37,2 +37,19 @@ chai-changes

### when
Executes the build up pre- and post-conditions. First it executes the
pre-conditions, then it will execute the provided callback. And after
the callback it will assert the post-conditions. It will change the
object in the assertion chain to the result of the callback.
When the callback returns a promise, the post-conditions are executed
when the promise is fulfilled.
Since the 'object' in the assertion chain is changed after the when, you
can chain [chai-as-promised](https://github.com/domenic/chai-as-promised) matchers too, like:
`(-> result).should.change.to(4).when(-> object.methodThatReturnsPromise()).and.notify(done)`
This makes this mechanism also compatible with
[mocha-as-promised](https://github.com/domenic/mocha-as-promised)
### `change`

@@ -39,0 +56,0 @@

@@ -20,36 +20,59 @@ // Generated by CoffeeScript 1.3.3

});
it('checks conditions after promise fulfilled', function(done) {
var def, result;
it('changes the object in the assert chain to the callback result', function() {
var result;
result = 1;
def = window.when.defer();
expect(function() {
return expect(function() {
return result;
}).to.change.when((function() {
return def.promise;
}), {
notify: done
});
result += 1;
return def.resolve();
}).not.to.change.when(function() {}).and.not.be.defined;
});
return it('returns error to notify when conditions after promise fail', function(done) {
var callCheck, def, result;
callCheck = function(arg) {
try {
arg.should.eql(new Error('expected `result;` to change, but it stayed 1'));
return done();
} catch (error) {
return done(new Error(error));
}
};
result = 1;
def = window.when.defer();
expect(function() {
return result;
}).to.change.when((function() {
return def.promise;
}), {
notify: callCheck
return describe('with promises', function() {
it('checks conditions after promise resolved', function(done) {
var def, result;
result = 1;
def = window.when.defer();
expect(function() {
return result;
}).to.change.when((function() {
return def.promise;
}), {
notify: done
});
result += 1;
return def.resolve();
});
return def.resolve();
it('checks conditions after promise is rejected', function(done) {
var def, result;
result = 1;
def = window.when.defer();
expect(function() {
return result;
}).to.change.when((function() {
return def.promise;
}), {
notify: done
});
result += 1;
return def.reject();
});
return it('returns error to notify when conditions after promise fail', function(done) {
var callCheck, def, result;
callCheck = function(arg) {
try {
arg.should.eql(new Error('expected `result;` to change, but it stayed 1'));
return done();
} catch (error) {
return done(new Error(error));
}
};
result = 1;
def = window.when.defer();
expect(function() {
return result;
}).to.change.when((function() {
return def.promise;
}), {
notify: callCheck
});
return def.resolve();
});
});

@@ -56,0 +79,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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