Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Describe provides a simple method for testing asynchronous and synchronous code within JavaScript projects.
describe( groupName, tests[, options] );
this.expect
.describe.config( key, value )
Sets the global configuration for tests.
this.expect( subject, expected )
describe("assertions", {
'basic synchronous expectation': function() {
this.expect(42, 42);
}
});
By passing this.expect as the callback parameter to an asynchronous function, describe will know to wait for the result of the operation before checking to see if the result matches what was expected.
this.expect( expected )
function addNumbersAsync(a, b, callback) {
callback(a+b);
}
describe("assertions", {
'basic asynchronous expectation': function() {
addNumbersAsync(2, 2, this.expect(4));
}
});
function addNumbersAsync(a, b, callback) {
callback(null, a+b);
}
describe("assertions", {
'basic asynchronous expectation': function() {
addNumbersAsync(2, 2, this.expect(4));
}
}, { callbackMode: 'node' });
function addThingsPromise() {
var n = 0;
for (var i in arguments) n+=arguments[i];
return {
then: function(success, failure) {
success(n);
}
};
}
describe("promise callback style", {
'promises-style addition': function() {
this.expect(addThingsPromise(2, 2), 4);
}
}, {
callbackMode: 'promises'
});
An asynchronous method. Calls back with the results of all tests described up to that point. You should probably wait until you're done defining tests to call this.
{
passed: 1,
total: 2,
results: {
"sample test group": {
passed: 1,
total: 2,
results: {
"this test passed because its error is null": null,
"this test failed because there's an error": "Error or message"
}
}
}
}
Gets the results and outputs them either to the DOM or the console.
Each test group supports beforeEach, afterEach, beforeAll, and afterAll as test hooks.
(function() {
var arr = [], bowties;
describe('array stuff', {
beforeAll: function() {
bowties = 'cool';
},
beforeEach: function() {
arr = arr.concat(1,2,3);
},
afterEach: function() {
arr = [];
},
afterAll: function() {
tests = null;
},
'bowties are cool': function() {
this.expect(bowties, 'cool');
},
'arrays have three things': function() {
this.expect(arr.length, 3);
arr.push(5);
},
'arrays still have three things': function() {
this.expect(arr.length, 3);
}
});
}());
FAQs
An extremely lightweight method for running tests.
We found that describe demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.